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
|
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.
|