#1
  1. cave painting, the 1st Opn Src
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2003
    Posts
    532
    Rep Power
    0
    [[ split from http://forums.devshed.com/xml-progra...on-808394.html --requinix ]]
    Originally Posted by requinix
    You can't really do JOINs, but you can search for nodes that match a condition.
    I'm trying to do a fair amount of data manipulation with xml files, if you can't 'join', how much transformation\query can you do?

    I don't want to suck the xml into mysql, but it almost seems worth it to get the data results I'm looking for.

    Is there a compelling reason not to manipulate the xml in a db and spit back the results?
    Last edited by requinix; May 24th, 2011 at 03:55 PM.
    Curious by Nature,
    Linux by Choice
    Lawson ERP reference tools: Lawsuss.com
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,053
    Rep Power
    9398
    It depends. What does your XML look like and what are you trying to get from it?
  4. #3
  5. cave painting, the 1st Opn Src
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2003
    Posts
    532
    Rep Power
    0
    It is fairly complex from the system and I want to do some level of display and modification.
    I'll keep plugging away at it.
    Curious by Nature,
    Linux by Choice
    Lawson ERP reference tools: Lawsuss.com
  6. #4
  7. cave painting, the 1st Opn Src
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2003
    Posts
    532
    Rep Power
    0

    Multi template with 'join'


    [[ thread merged... --requinix ]]

    I have a file with printers and rules in it. I need to output the printer that matches it's rules.

    xml
    Code:
    <SEC>
      <SECCLASS >
       <AttrType>ENV</AttrType>
       <AttrName>PROD</AttrName>
       <Attrref></Attrref>
      </SECCLASS>
      <SECCLASS>
        <AttrType>PRT</AttrType>
        <AttrName>tr_001</AttrName>
       <Attrref>g_01</Attrref>
      </SECCLASS>
      <SECCLASS>
        <AttrType>PRT</AttrType>
        <AttrName>tr_002</AttrName>
       <Attrref>g_02</Attrref>
      </SECCLASS>
      <SECCLASS>
        <AttrType>ITEM</AttrType>
        <AttrName>class</AttrName>
       <Attrref></Attrref>
      </SECCLASS>
    <SEC>
    <RULE>
       <Attrrule>Portrait</Attrrule>
       <Attrref>g_01</Attrref>
    </RULE>
    <RULE>
       <Attrrule>Landscape</Attrrule>
       <Attrref>g_02</Attrref>
    </RULE>
    <RULE>
       <Attrrule>A17</Attrrule>
       <Attrref>g_03</Attrref>
    </RULE>
    <RULE>
       <Attrrule>Color</Attrrule>
       <Attrref>g_04</Attrref>
    </RULE>
    xsl
    Code:
    <xsl:template match="SEC">
      <xsl:apply-templates select="SECCLASS/ATTR[AttrType ='PRT']"/>
      <xsl:apply-templates select="SECCLASS/ATTR[Attrref = RULE/Attrref]"/>
    </xsl:template>
      <xsl:template match="SECCLASS/ATTR">
       <tr>
        <td>
         <xsl:value-of select="SEC/SECCLASS/AttrName"/>
       </td>
        <td>
         <xsl:value-of select="RULE/Attrrule"/>
       </td>
      </tr>
    </xsl:template>
    So IF it is a Printer, then I want the Printer Name and the corresponding Printer Rule. I just don't know if I can have multiple selects in a template, and can I mix the nodes?
    Last edited by requinix; May 25th, 2011 at 01:32 PM.
    Curious by Nature,
    Linux by Choice
    Lawson ERP reference tools: Lawsuss.com
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2009
    Posts
    191
    Rep Power
    49
    your xml file ist not valid
    think like xsl in xml so it will going on

    every xml file must have a root element

    so you have xml like this
    Code:
    <?xml version="1.0"?>
    <root>
    	<SEC>
    		<SECCLASS>
    			<AttrType>ENV</AttrType>
    			<AttrName>PROD</AttrName>
    			<Attrref></Attrref>
    		</SECCLASS>
    		<SECCLASS>
    			<AttrType>PRT</AttrType>
    			<AttrName>tr_001</AttrName>
    			<Attrref>g_01</Attrref>
    		</SECCLASS>
    		<SECCLASS>
    			<AttrType>PRT</AttrType>
    			<AttrName>tr_002</AttrName>
    			<Attrref>g_02</Attrref>
    		</SECCLASS>
    		<SECCLASS>
    			<AttrType>ITEM</AttrType>
    			<AttrName>class</AttrName>
    			<Attrref></Attrref>
    		</SECCLASS>
    	</SEC>
    	<RULE>
    		<Attrrule>Portrait</Attrrule>
    		<Attrref>g_01</Attrref>
    	</RULE>
    	<RULE>
    		<Attrrule>Landscape</Attrrule>
    		<Attrref>g_02</Attrref>
    	</RULE>
    	<RULE>
    		<Attrrule>A17</Attrrule>
    		<Attrref>g_03</Attrref>
    	</RULE>
    	<RULE>
    		<Attrrule>Color</Attrrule>
    		<Attrref>g_04</Attrref>
    	</RULE>
    </root>
    xsl to testing
    Code:
    <?xml version="1.0"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    	<xsl:output indent="yes" method="html"/>
    	<xsl:template match="/">
    		<html>
    			<style type="text/css">table
    		{
    		border:solid 1px black;
    		}
    		th,td
    		{
    		border:solid 1px black;
    		}
    		.head
    		{
    		background-color:#9acd32;
    		}</style>
    			<body>
    				<h2>Printers</h2>
    				<table>
    					<tr class="head">
    						<th>Printers</th>
    						<th>Info</th>
    						<th>Rule</th>
    					</tr>
    					<xsl:apply-templates select="root"/>
    				</table>
    			</body>
    		</html>
    	</xsl:template>
    	<xsl:template match="root">
    		<xsl:apply-templates select="SEC"/>
    	</xsl:template>
    	<xsl:template match="SEC">
    		<xsl:apply-templates select="SECCLASS[AttrType = 'PRT']"/>
    	</xsl:template>
    	<xsl:template match="SECCLASS">
    		<tr>
    			<td>
    				<xsl:value-of select="AttrType"/>
    			</td>
    			<td>
    				<xsl:value-of select="AttrName"/>
    			</td>
    			<!--
    			<td>
    				<xsl:value-of select="Attrref"/>
    			</td>
    			-->
    			<xsl:variable name="attrref" select="Attrref"/>
    			<xsl:apply-templates select="../../RULE[Attrref=$attrref]"/>
    		</tr>
    	</xsl:template>
    	<xsl:template match="RULE">
    		<td>
    			<xsl:value-of select="Attrrule"/>
    		</td>
    	</xsl:template>
    </xsl:stylesheet>
    result

    Code:
    <html>
      <style type="text/css">table
    		{
    		border:solid 1px black;
    		}
    		th,td
    		{
    		border:solid 1px black;
    		}
    		.head
    		{
    		background-color:#9acd32;
    		}
      </style>
      <body>
        <h2>Printers</h2>
        <table>
          <tr class="head">
            <th>Printers</th>
            <th>Info</th>
            <th>Rule</th>
          </tr>
          <tr>
            <td>PRT</td>
            <td>tr_001</td>
            <td>Portrait</td>
          </tr>
          <tr>
            <td>PRT</td>
            <td>tr_002</td>
            <td>Landscape</td>
          </tr>
        </table>
      </body>
    </html>
    Helmut Hagemann Germany

    fallen to the bottom of the facts?
    I reach my hand and we go together


    wer lesen und google kann ist klar im Vorteil
    who read and google is able is clear in the advantage
  10. #6
  11. cave painting, the 1st Opn Src
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2003
    Posts
    532
    Rep Power
    0
    I'm sorry, yes there was a root to the xml. I cut the portion out that I was testing. Thanks for being able to fix that and answer my question.
    Curious by Nature,
    Linux by Choice
    Lawson ERP reference tools: Lawsuss.com
  12. #7
  13. cave painting, the 1st Opn Src
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2003
    Posts
    532
    Rep Power
    0
    Code:
    	<xsl:template match="SECCLASS">
                     <xsl:for-each value="AttrName">
                      <xsl:sort value="AttrName">
    		<tr>
    			<td>
    				<xsl:value-of select="AttrType"/>
    			</td>
    			<td>
    				<xsl:value-of select="AttrName"/>
    			</td>
    			<!--
    			<td>
    				<xsl:value-of select="Attrref"/>
    			</td>
    			-->
    			<xsl:variable name="attrref" select="Attrref"/>
    			<xsl:apply-templates select="../../RULE[Attrref=$attrref]"/>
    		</tr>
             </xsl:for-each>
    	</xsl:template>
    So I added a SORT to the template and it blew up. Where to I put a sort on the AttrName to get an ordered list back?
    Curious by Nature,
    Linux by Choice
    Lawson ERP reference tools: Lawsuss.com
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2009
    Posts
    191
    Rep Power
    49
    you have to make yourself what
    and not always ask

    and please work with template thoughtless
    and not as a programmer

    not use the for-each is drawn off as a programmer


    Code:
    <?xml version="1.0"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    	<xsl:output indent="yes" method="html"/>
    	<xsl:template match="/">
    		<html>
    			<style type="text/css">table
    		{
    		border:solid 1px black;
    		}
    		th,td
    		{
    		border:solid 1px black;
    		}
    		.head
    		{
    		background-color:#9acd32;
    		}</style>
    			<body>
    				<h2>Printers</h2>
    				<table>
    					<tr class="head">
    						<th>Printers</th>
    						<th>Info</th>
    						<th>Rule</th>
    					</tr>
    					<xsl:apply-templates select="root"/>
    				</table>
    			</body>
    		</html>
    	</xsl:template>
    	<xsl:template match="root">
    		<xsl:apply-templates select="SEC"/>
    	</xsl:template>
    	<xsl:template match="SEC">
    		<xsl:apply-templates select="SECCLASS[AttrType = 'PRT']">
    		<xsl:sort select="AttrName" order="ascending"/>
    		</xsl:apply-templates>
    	</xsl:template>
    	<xsl:template match="SECCLASS">
    		<tr>
    			<td>
    				<xsl:value-of select="AttrType"/>
    			</td>
    			<td>
    				<xsl:value-of select="AttrName"/>
    			</td>
    			<!--
    			<td>
    				<xsl:value-of select="Attrref"/>
    			</td>
    			-->
    			<xsl:variable name="attrref" select="Attrref"/>
    			<xsl:apply-templates select="../../RULE[Attrref=$attrref]"/>
    		</tr>
    	</xsl:template>
    	<xsl:template match="RULE">
    		<td>
    			<xsl:value-of select="Attrrule"/>
    		</td>
    	</xsl:template>
    </xsl:stylesheet>
    Helmut Hagemann Germany

    fallen to the bottom of the facts?
    I reach my hand and we go together


    wer lesen und google kann ist klar im Vorteil
    who read and google is able is clear in the advantage

IMN logo majestic logo threadwatch logo seochat tools logo