Jump to content

XSLT value of select problem (xml to html table)


Guest Guinnub

Recommended Posts

Guest Guinnub

im new to xsl, and i have a question.i have an export from a database, and want to see it in a html table. In the table i m trying to get some product info. all data in command/product is not a problem. but somehow i am not able to get the ClassificationGroup/DecsShort (group20 or group10). wich is in Command/ClassificationGroup the groupid is in command/product but the name is in Command/ClassificationGroup. and i want the name in de table.<td><xsl:value-of select="Command/ClassificationGroup[@id=$ClassificationGroup]/DescShort[@languageId=en]"/></td> doesnt work.it should look like this, but i cant fill the last columnProdId Options Length GroupId ClassificationGroup 0310003 Many options 2.13 10 Group10 0310004 More options 1.83 20 Group20outside the "for each" i can call the data but i cant get it in the table. I hope someone can help me. ps it is not an option to change the xml, it is a standard export from a database. XML

<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="forum.xsl"?><CML version="1.0">	<Command>      <ClassificationGroup id="10">         <DescShort languageId="en">Group10</DescShort>         <CreatedOn>2010-07-13 15:40:58.0</CreatedOn>      </ClassificationGroup>	</Command>	<Command>      <ClassificationGroup id="20">         <DescShort languageId="en">Group20</DescShort>         <CreatedOn>2010-07-13 15:40:58.0</CreatedOn>      </ClassificationGroup>	</Command>	<Command>      <Product id="0310003">            <AttributeValues>				<AttributeValue attributeId="options" languageId="en">Many options</AttributeValue>				<AttributeValue attributeId="length_m">2.13</AttributeValue>            </AttributeValues>			<ClassificationGroupAssociation>               <ClassificationGroup id="10">                  <Classification id="Horse"/>               </ClassificationGroup>            </ClassificationGroupAssociation>       </Product>	</Command>	<Command>      <Product id="0310004">            <AttributeValues>				<AttributeValue attributeId="options" languageId="en">More options</AttributeValue>				<AttributeValue attributeId="length_m">1.83</AttributeValue>			</AttributeValues>			<ClassificationGroupAssociation>               <ClassificationGroup id="20">                  <Classification id="Donkey"/>               </ClassificationGroup>            </ClassificationGroupAssociation>        </Product>	</Command>.</CML>

XSL

<?xml version="1.0" encoding="ISO-8859-1"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">	<xsl:output method="html"/>			<xsl:template match="/">	<xsl:apply-templates select="CML"/>	</xsl:template>	<xsl:template match="CML">  <table border="1" cellpadding="5" cellspacing="0">   <tr>    <th>ProdId</th>    <th>Options</th>    <th>Length</th>    <th>GroupId</th>    <th>ClassificationGroup</th>	</tr>    	<body>		<xsl:for-each select="./Command/Product">			<tr>				<xsl:call-template name="fillTable"/>			</tr>		</xsl:for-each>						<tr>				<xsl:call-template name="test"/>			</tr>		</body>  </table></xsl:template><xsl:template name="fillTable" >	      <td><xsl:value-of select="@id"/></td>	 <td><xsl:value-of select="./AttributeValues/AttributeValue[@attributeId='options']" /></td>	 <td><xsl:value-of select="./AttributeValues/AttributeValue[@attributeId='length_m']" /></td>		<xsl:variable name="ClassificationGroup" select="./ClassificationGroupAssociation/ClassificationGroup/@id"/>	 <td><xsl:value-of select="$ClassificationGroup" /></td>	 <td><xsl:value-of select="Command/ClassificationGroup[@id=$ClassificationGroup]/DescShort[@languageId='en']"/></td>	</xsl:template>	<xsl:template name="test" >	     	<td><xsl:value-of select="Command/ClassificationGroup[@id=10]/DescShort[@languageId='en']"/></td>		</xsl:template>	</xsl:stylesheet>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...