Reputation: 13
I am trying to transform XML using XSLT. But whole node FKN-VERS empty . can any one suggest please .. my xml-code is:
<?xml version="1.0" encoding="UTF-8"?>
<Versions>
<FirstVersion >
<Element OriginalName="fin_Test" >
<ElementClass Name="TEST"/>
<ElementAttributes/>
</Element>
<Type Name="TEST" />
<LifecycleState Name="OPe" Lifecycle="STANDARD" />
<Predecessors>
<Predecessor Variant="BASE_RETEST1" Revision="1"/>
</Predecessors>
</FirstVersion>
</Versions>
my xsl code for transformation is:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/Versions[FirstVersion/Type/@Name='TEST']">
<DATA>
<xsl:attribute name="ID">10</xsl:attribute>
<FKN-VERS>
<FKN-VERS>
<xsl:for-each select=" Versions/FirstVersion/Predecessors">
<VERS-LABEL>
<xsl:value-of select="concat(@Variant, ';',@Revision)"/>
</VERS-LABEL>
</xsl:for-each>
</FKN-VERS>
</FKN-VERS>
</DATA>
</xsl:template>
</xsl:stylesheet>
Output:
<ID="10">
<FKN-VERS>
<FKN-VERS/>
</FKN-VERS>
</DATA>
Upvotes: 0
Views: 67
Reputation: 111491
Change your for-each
statement,
<xsl:for-each select=" Versions/FirstVersion/Predecessors">
to
<xsl:for-each select="FirstVersion/Predecessors/Predecessor">
because the current node will already be at a Versions
element when the containing template matches and because you wish to iterate over Predecessor
elements, not the containing Predecessors
elements.
Upvotes: 1
Reputation: 101652
It looks to me like your selection path starts one node too high up, and ends one node too high up. Try this:
<xsl:for-each select="FirstVersion/Predecessors/Predecessor">
<VERS-LABEL>
<xsl:value-of select="concat(@Variant, ';',@Revision)"/>
</VERS-LABEL>
</xsl:for-each>
Upvotes: 1