I'm new to XSLT and i got to understand from my team that the current xml parser we have supports only version 1.0. I would need help here to convert my current xslt 2.0 code to version 1.0
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/Root">
<!-- header -->
<xsl:text>id|parent_id</xsl:text>
<xsl:value-of select="$newline"/>
<!-- data -->
<xsl:for-each select="Package">
<xsl:variable name="b-id" select="Business_ID" />
<!-- TPFC data -->
<xsl:for-each select="TPFC">
<xsl:variable name="total_level" select="count(.//.//Parent)+1"/>
<xsl:call-template name="prod-family">
<xsl:with-param name="total_level" select="$total_level"/>
<xsl:with-param name="b_id" select="$b-id"/>
</xsl:call-template>
<xsl:for-each select="//Parent">
<!-----Question 2------->
<xsl:call-template name="prod-family">
<xsl:with-param name="total_level" select="$total_level"/>
<xsl:with-param name="b_id" select="$b-id"/>
</xsl:call-template>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
<!-----Question 1------->
<xsl:template name="prod-family">
<xsl:param name="total_level"/>
<xsl:param name="b_id"/>
<xsl:value-of select="reverse(.//Parent/Name), translate(Name,' ','')" separator="_" />
<xsl:value-of select="$separator"/>
<xsl:value-of select="reverse(.//Parent/Name)" separator="_" />
<xsl:value-of select="$separator"/>
<xsl:value-of select="$newline"/>
</xsl:template>
</xsl:stylesheet>
XML For the above is
<?xml version="1.0" encoding="UTF-8"?>
<Root
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Package ID="1122" BusinessID="001233" Version="19.0.2" xsi:type="Doms">
<Name>ABC</Name>
<Description> Desc sample</Description>
<Category>54</Category>
<Business_ID>001233</Business_ID>
<TPFC ID="76" xsi:type="TPFC" Pattern="Th_Branch">
<Name>AM</Name>
<Parent ID="11d" xsi:type="TPFC" Pattern="Th_Branch">
<Description>Mob1</Description>
<Name>Mob1</Name>
<Parent ID="12F" xsi:type="TPFC" Pattern="Th_Branch">
<Description>Mob2</Description>
<Name>Mob2</Name>
</Parent>
</Parent>
</TPFC>
</Package>
</Root>
This is the result
| id | parent_id |
| Mob2_Mob1_AM | Mob2_Mob1 |
| Mob2_Mob1 | Mob2 |
| Mob2 | |
In the above example, I have implemented the concatenation using XSLT 2.0 in two places (check template - prod-family ) where
id - Concatenation of all names from its root parent to current name in the below example it will be Mob2_Mob1_AM parent_id - Concatenation of all parent names from its root parent
- Can anyone help me out on how to implement concat using for-each in XSLT 1.0 version for the above two cases
- Is call-template along with params supported in XSLT 1.0 as well?
count(.//.//Parent)
is hopelessly misguided in both 1.0 and 2.0. It's just a longwinded and potentially very inefficient way of sayingcount(.//Parent)
. (Inefficient because for every descendant, you collect all its descendants, and then eliminate all the duplicates). – Michael Kay