Using XSL to filter the data from XML
-
Hello, I am storing the database data in the XML file. Using the XSL file I want to retrieve the selected data from the XML file. I have tried using , , , but I am not getting the desired results. If I use , the page is not rendered & the drop down control is displayed as a plain text. If I use , the condition is not being tested. Can anypne tell me exactly what could be the problem? Thanks in advance Hitesh
-
Hello, I am storing the database data in the XML file. Using the XSL file I want to retrieve the selected data from the XML file. I have tried using , , , but I am not getting the desired results. If I use , the page is not rendered & the drop down control is displayed as a plain text. If I use , the condition is not being tested. Can anypne tell me exactly what could be the problem? Thanks in advance Hitesh
It would help a lot if you could provide an example of your XML and what you are trying to retrieve. <tip>Write < when you want to show the < character.</tip> ;)
-
It would help a lot if you could provide an example of your XML and what you are trying to retrieve. <tip>Write < when you want to show the < character.</tip> ;)
Hi, Thanks for the reply. Following is the part of the code Credit Card Option1 D2 Credit Card Option1 D2 Credit Card Option1 D2 CardType is the tag in my XML file. Based on the value of CardType selected, I want to display the values from the XML file. Let me know if you can understand this. I wanted to attach my .xsl file but there is no way I can attach the file. Thanks Hitesh
-
Hi, Thanks for the reply. Following is the part of the code Credit Card Option1 D2 Credit Card Option1 D2 Credit Card Option1 D2 CardType is the tag in my XML file. Based on the value of CardType selected, I want to display the values from the XML file. Let me know if you can understand this. I wanted to attach my .xsl file but there is no way I can attach the file. Thanks Hitesh
I'm guessing your XML looks something like this:
<cards>
<card><CardType>1</CardType>
<data>
<record>
<field1>
<CardLicenceOption>1</CardLicenceOption>
<CardLicenceOptionDescription>Credit</CardLicenceOptionDescription>
</field1>
<field1>
<CardLicenceOption>2</CardLicenceOption>
<CardLicenceOptionDescription>Charge</CardLicenceOptionDescription>
</field1>
</record>
</data>
</card>
<card><CardType>3</CardType>
<CardOptionParent1>1</CardOptionParent1>
<CardOptionDescription>Cash</CardOptionDescription>
</card>
</cards>It looks like you're using incorrect paths to access your XML elements. The following XSLT should work:
<xsl:for-each select="//card">
<tr><td width="50%">Credit Card Option1
xsl:choose<xsl:when test="CardType=3">
<xsl:element name="select">
<xsl:attribute name="name">D2</xsl:attribute>
<xsl:element name="option">
<xsl:attribute name="value">
<xsl:value-of select="CardOptionParent1" />
</xsl:attribute>
<xsl:value-of select="CardOptionDescription" />
</xsl:element>
</xsl:element>
</xsl:when><xsl:when test="CardType=4">
<xsl:element name="select">
<xsl:attribute name="name">D2</xsl:attribute>
<xsl:element name="option">
<xsl:attribute name="value">
<xsl:value-of select="CardOptionParent2" />
</xsl:attribute>
<xsl:value-of select="CardOptionDescription" />
</xsl:element>
</xsl:element>
</xsl:when>xsl:otherwise
<xsl:element name="select">
<xsl:attribute name="name">D2</xsl:attribute>
<xsl:for-each select="data/record/field1">
<xsl:element name="option">
<xsl:attribute name="value">
<xsl:value-of select="CardLicenceOption"/>
</xsl:attribute>
<xsl:value-of select="CardLicenceOptionDescription" />
</xsl:element>
</xsl:for-each>
</xsl:element>
</xsl:otherwise>
</xsl:choose>
</td></tr>
</xsl:for-each>