I am using ant1.8 on ubuntu 10.10 and also xslt1.0.
I have 2 lists of items:
Code:
ProductID=8901|8902|8903|8904|8905|8906|8907|8908|9089
ProductDisplayName=Song1|Song2|Song3|Song4|Song5|Song6|Song7|Song8|Song9
That I need to transform to look like:
Code:
<Product>
<subscription/>
<ID>8901</ID>
<title>Song1</title>
</Product>
<Product>
<subscription/>
<ID>8902</ID>
<title>Song2</title>
</Product>
<Product>
<subscription/>
<ID>8903</ID>
<title>Song3</title>
</Product>
And so on and so forth. I feel like I am close but the loop that I am using is causing a stack overflow. Here is my template that i created:
Code:
<xsl:template name="parseSubscription">
<xsl:param name="parseId" select="normalize-space($ProductID)" />
<xsl:param name="parseDisplayName" select="normalize-space($ProductDisplayName)" />
<xsl:choose>
<xsl:when test="nscl:capitalize($ProductType) = 'Free'">
<Product>
<freeAccess />
</Product>
</xsl:when>
<xsl:otherwise>
<xsl:if test="string-length($parseId) > 0">
<Product>
<subscription/>
<ID>
<xsl:choose>
<xsl:when test="contains($parseId, '|')">
<xsl:value-of select="normalize-space(substring-before($parseId, '|'))" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="normalize-space($parseId)" />
</xsl:otherwise>
</xsl:choose>
</ID>
<title>
<xsl:choose>
<xsl:when test="contains($parseDisplayName, '|')">
<xsl:value-of select="normalize-space(substring-before($parseDisplayName, '|'))" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="normalize-space($parseDisplayName)" />
</xsl:otherwise>
</xsl:choose>
</title>
</Product>
<!-- Recurse -->
<xsl:call-template name="parseSubscription">
<xsl:with-param name="parseId" select="substring-after(normalize-space($ProductID), '|')" />
<xsl:with-param name="parseDisplayName" select="substring-after(normalize-space($ProductDisplayName), '|')" />
</xsl:call-template>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
and how it is called:
Code:
<xsl:call-template name="parseSubscription">
<xsl:with-param name="parseId" select="$ProductID" />
<xsl:with-param name="parseDisplayName" select="$ProductDisplayName" />
</xsl:call-template>
If I remove the recursive call ant is able to compile the xsl and transform the file just fine, but of course I only get the first pair:
Code:
<Product>
<subscription/>
<ID>8901</ID>
<title>Song1</title>
</Product>
and of course I need it to continue to loop through until it reaches the end of the list. I have some kind of issue (obviously), can anyone help me identify it? Or perhaps just a better approach?
Thanks!