<xsl:for-each select ="block4">
<xsl:choose>
<xsl:when test="tag[name = '57A']">
<xsl:value-of select="value"/>
</xsl:when>
<xsl:when test="tag[name = '57D'] ">
<xsl:value-of select="value"/>
</xsl:when>
</xsl:choose>,<xsl:text/>
</xsl:for-each>
I have written my xslt like this. It's not working properly for this xml:
<tag>
<name>57A</name>
<value>NORTESMM</value>
</tag>
Sometimes the name of tags will change. It should be either 57A or 57D, as indicated in XSLT above. But it's not generating the proper outcome.
It can differ depending on how
<block4>
and<tag>
tags are structured.Anyway I suggest you to learn XSLT first, at least the basics, and then to use it.
This is the shortest and the "most in the spirit of XSLT" solution:
when applied on this XML document:
the wanted, correct result is produced:
Do note:
We use and override the identity rule. This is the most fundamental and powerful XSLT design pattern.
We don't use
<xsl:for-each>
and we don't use XSLT conditional instructions.Solution 2:
When applied on the same XML document (above), again the wanted, correct result is produced:
Do note: This solution can be used when we want to treat many different possible values of
tag/name
. We use a table for the matching values and only a single overriding template.Change your select to:
Complete program:
XML:
XSL:
OUTPUT:
Try this
You can test your XSLT with a simple XML, create two files test.xsl and data.xml and then open data.xml in Firefox for example:
data.xml
test.xsl
try