IMPORTANT:
this is not a Support Forum! Experienced users might answer from time to time questions posted here. If you need a professional and reliable answer, or if you want to report a bug, please contact Altova Support instead.

How to increase variable count? Options · View
plugincms
Posted: Thursday, January 29, 2009 10:17:56 AM
Rank: Newbie

Joined: 1/29/2009
Posts: 1
Dear Experts,
I am new to XSLT programming.
I have the following requirement to convert the below xml to simple text based on the true / false values in the element values. XML element names are fixed( Monday, tuesday...friday...always 5 elemnets will be there)


<page_content>
<content_list monday="true" tuesday="false" wednesday="true" thursday="fasle" Friday="true">
</page_content>

OUT PUT:
1 Monday
2 Wednesday
3 Friday


I am trying to achive this by the following but not succeded

<xsl:template name='getContent'>
<xsl:variable name="i">0</xsl:variable>
<xsl:if test="content_list /@Monday='true'">
{$i+1} Monday

</xsl:if>

<xsl:if test="content_list /@Tuesday='true'">
{$i+1} Tuesday

</xsl:if>

<xsl:if test="content_list /@Wednesday='true'">
{$i+1} Wednesday

</xsl:if>

<xsl:if test="content_list /@Thursday='true'">
{$i+1} Thursday

</xsl:if>

<xsl:if test="content_list /@Friday='true'">
{$i+1} Friday

</xsl:if>
</xsl:template>


Thanks in advance!

Regards,
Akhil
JohnBampton
Posted: Tuesday, February 10, 2009 1:20:30 PM
Rank: Member

Joined: 2/10/2009
Posts: 11
The solution using Saxon XSLT and XQuery processor is:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0" xmlns:saxon="http://saxon.sf.net/"
extension-element-prefixes="saxon">

<xsl:variable name="counter" select="0" saxon:assignable="yes"/>

<xsl:template match="/">
<xsl:if test="page_content/content_list/@monday = 'true'">
<saxon:assign name="counter" select="$counter+1"/>
<xsl:value-of select="$counter"></xsl:value-of> Monday
</xsl:if>
<xsl:if test="page_content/content_list/@tuesday = 'true'">
<saxon:assign name="counter" select="$counter+1"/>
<xsl:value-of select="$counter"></xsl:value-of> Tuesday
</xsl:if>
<xsl:if test="page_content/content_list/@wednesday = 'true'">
<saxon:assign name="counter" select="$counter+1"/>
<xsl:value-of select="$counter"></xsl:value-of> Wednesday
</xsl:if>
<xsl:if test="page_content/content_list/@thursday = 'true'">
<saxon:assign name="counter" select="$counter+1"/>
<xsl:value-of select="$counter"></xsl:value-of> thursday
</xsl:if>
<xsl:if test="page_content/content_list/@Friday = 'true'">
<saxon:assign name="counter" select="$counter+1"/>
<xsl:value-of select="$counter"></xsl:value-of> Friday
</xsl:if>
</xsl:template>
</xsl:stylesheet>


Cheers, John Bampton.
Users browsing this topic
guest

Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Use of the Altova User Forum(s) is governed by the Altova Terms of Use.