Reputation: 135
i'm new to xsl-fo. In my problem there are 3 sibling tags, one of them has an attribute. I have to print the one with the attribute first and then the other two. My problem is that my results aren't showing and i've tried when and if. Heres my code:
<fo:block>
<xsl:for-each select="platforms/platform">
<xsl:choose>
<xsl:when test="@highestRated">
<xsl:value-of select="platform"/>
</xsl:when>
</xsl:choose>
</xsl:for-each>
! Also available on
<xsl:for-each select="platforms/platform">
<xsl:choose>
<xsl:when test="not(@*)">
<xsl:value-of select="platform"/>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</fo:block>
and heres an example of the siblings:
<platforms>
<platform>PC</platform>
<platform highestRated="true">PS3</platform>
<platform>X360</platform>
</platforms>
i can't just use them in the order they appear here because each set of siblings are in a different order. I also get no errors and the rest of the document displays perfectly, they just won't show the results.
Thank you
Upvotes: 0
Views: 292
Reputation: 126722
As others have said, your main problem is that you have select="platform"
which is looking for an element /platforms/platform/platform
which doesn't exist. Also an xsl:choose
with only one xsl:when
is the same as an xsl:if
. (It is useful to use xsl:when
if you want a else condition, which xsl:if
doesn't provide. Use xsl:choose
/ xsl:when
/ xsl:otherwise
instead.) But in this case you may as well select only the elements you want using a predicate; then there is no need for a conditional.
Here is some code that does what you need.
<?xml version="1.0" encoding="UTF-8" ?>
<!-- New document created with EditiX at Wed Mar 21 21:51:52 GMT 2012 -->
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:variable name="nl">
<xsl:text>
</xsl:text>
</xsl:variable>
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<fo:block>
<xsl:value-of select="$nl"/>
<xsl:for-each select="platforms/platform[@highestRated]">
<xsl:value-of select="."/>
<xsl:value-of select="$nl"/>
</xsl:for-each>
<xsl:text>! Also available on</xsl:text>
<xsl:value-of select="$nl"/>
<xsl:for-each select="platforms/platform[not(@highestRated)]">
<xsl:value-of select="."/>
<xsl:value-of select="$nl"/>
</xsl:for-each>
</fo:block>
</xsl:template>
</xsl:stylesheet>
output
<?xml version="1.0" encoding="utf-8"?>
<fo:block xmlns:fo="http://www.w3.org/1999/XSL/Format">
PS3
! Also available on
PC
X360
</fo:block>
Upvotes: 2
Reputation: 10163
Try changing
<xsl:value-of select="platform"/>
to
<xsl:value-of select="."/>
Hope that helps
Upvotes: 0