I have an xml file which is at http://ift.tt/ZkPg3v
I am using the following xsl with Saxon-HE and while it doesn't produce errors (so it should be correct syntax) none of the xsl:when statements seem to be evaluating as true because all the output tags are being wrapped in <bodytext></bodytext> according the xsl:otherwise statement.
The intended effect of these xsl:when statements is some variation of the following
IF a:t element has a <p.sld> ancestor AND has an <r> ancestor which has an immediately-preceding sibling element which has an attribute:value pair of lvl='1' THEN output the contents of that a:t wrapped in <bulleted></bulleted> OTHERWISE output the contents of that a:t wrapped in <bodytext></bodytext>
the variations on what tag the output should be wrapped in depend on if the ancestor is <p.sld> or <p.notes> and whether the lvl property has a value of 1, 2, or 3
Here's my XSL
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://ift.tt/tCZ8VR" xmlns:fo="http://ift.tt/vyPH5E" xmlns:a="http://ift.tt/1dB6t9q" xmlns:r="http://ift.tt/1bA4cfb" xmlns:p="http://ift.tt/1eCLHM2">
<xsl:output method="xml"/>
<xsl:template match="/">
<document>
<xsl:apply-templates select="//a:t"/>
</document>
</xsl:template>
<xsl:template match="//a:t">
<xsl:choose>
<xsl:when test="(count(ancestor::p:sld) > 0) and (count(ancestor::r/preceding-sibling::node[1][@lvl='1'])) > 0">
<bulleted><xsl:value-of select="."/></bulleted>
</xsl:when>
<xsl:when test="(count(ancestor::p:sld) > 0) and (count(ancestor::r/preceding-sibling::node[1][@lvl='2'])) > 0">
<bulleted2><xsl:value-of select="."/></bulleted2>
</xsl:when>
<xsl:when test="(count(ancestor::p:notes) > 0) and (count(ancestor::r/preceding-sibling::node[1][@lvl='2'])) > 0">
<bulleted><xsl:value-of select="."/></bulleted>
</xsl:when>
<xsl:when test="(count(ancestor::p:notes) > 0) and (count(ancestor::r/preceding-sibling::node[1][@lvl='3'])) > 0">
<bulleted2><xsl:value-of select="."/></bulleted2>
</xsl:when>
<xsl:otherwise>
<bodytext><xsl:value-of select="."/></bodytext>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
Here's the desired XML output:
<?xml version="1.0" encoding="UTF-8"?>
<document xmlns:fo="http://ift.tt/vyPH5E" xmlns:a="http://ift.tt/1dB6t9q" xmlns:r="http://ift.tt/1bA4cfb" xmlns:p="http://ift.tt/1eCLHM2">
<bodytext>header text</bodytext>
<bodytext>body text </bodytext>
<bodytext>body text </bodytext>
<bodytext>body text </bodytext>
<bulleted>bulleted text</bulleted>
<bulleted>bulleted text</bulleted>
<bulleted>bulleted text</bulleted>
<bulleted2>bulleted2 text</bulleted2>
<bulleted2>bulleted2 text</bulleted2>
<bulleted2>bulleted2 text</bulleted2>
<bulleted2>bulleted2 text</bulleted2>
<bulleted>bulleted text</bulleted>
<bulleted>bulleted text</bulleted>
<bulleted>bulleted text</bulleted>
<bulleted>bulleted text</bulleted>
<bodytext>body text</bodytext>
<bodytext>body text</bodytext>
<bodytext>footer text</bodytext>
<bodytext>10</bodytext>
<bodytext>10</bodytext>
<bodytext>notes header text</bodytext>
<bodytext>notes body text </bodytext>
<bodytext>notes body text </bodytext>
<bodytext>notes table header text</bodytext>
<bodytext>notes table header text</bodytext>
<bodytext>notes table body text</bodytext>
<bodytext>notes table body text</bodytext>
<bodytext>notes table body text</bodytext>
<bodytext>notes table body text</bodytext>
<bodytext>notes table body text</bodytext>
<bodytext>notes table body text</bodytext>
</document>
No comments:
Post a Comment