does anyone know how to skip part of an xml document when a particular tag is met? i've got an xml (WordML) document with if statements surrounded by <condition> tags as follows:
the purpose of the conditions is to be able to produce documents with different content depending on certain factors. in the example above, one block of text should be in the document if "MYNAME" (dataname/variable) is equal to "BOB", and another load of text if not.
i've also got an xml file (merge-data.xml) that actually holds the results of if statements (among other things). below is a short sample:
so when processing the document i need to refer to the data in the xml file above.
i've written a match template, but the condition tags (blocks) aren't being processed properly. i'm quite new to this stuff & am pretty stuck. i'm getting text from both the if & else blocks, plus the else block of text is being repeated 4 times, then the end of the if (tag) is hit 4 times!? the template is being applied whenever the tag exists within a <w:t> block using a simple <xsl:apply-templates/>. if anyone has any ideas i'd really appreciate the help!!
Code:
[teal]<!-- some document tags/text etc. -->[/teal]
<sdp:condition eval="MYNAME = 'BOB'"><<IF MYNAME = 'BOB'>></sdp:condition>
[teal]<!-- some document tags/text etc. -->[/teal]
<sdp:condition eval="ELSE"><<ELSE>><<IF MYNAME = 'BOB'>></sdp:condition>
[teal]<!-- some document tags/text etc. -->[/teal]
<sdp:condition eval="END"><<ENDIF>><<IF MYNAME = 'BOB'>></sdp:condition>
[teal]<!-- some document tags/text etc. -->[/teal]
the purpose of the conditions is to be able to produce documents with different content depending on certain factors. in the example above, one block of text should be in the document if "MYNAME" (dataname/variable) is equal to "BOB", and another load of text if not.
i've also got an xml file (merge-data.xml) that actually holds the results of if statements (among other things). below is a short sample:
Code:
<docpro-print-entry>
<dataset>
<condition ref="<<IF MYNAME = 'BOB'>>">TRUE</condition>
[teal]<!-- bla bla bla -->[/teal]
</dataset>
</docpro-print-entry>
so when processing the document i need to refer to the data in the xml file above.
i've written a match template, but the condition tags (blocks) aren't being processed properly. i'm quite new to this stuff & am pretty stuck. i'm getting text from both the if & else blocks, plus the else block of text is being repeated 4 times, then the end of the if (tag) is hit 4 times!? the template is being applied whenever the tag exists within a <w:t> block using a simple <xsl:apply-templates/>. if anyone has any ideas i'd really appreciate the help!!
Code:
<xsl:variable name="mergeData" select="document('merge-data.xml')"/>
<xsl:template match="sdp:condition">
<xsl:variable name="curNode" select="."/>
<xsl:choose>
<xsl:when test="$curNode/@eval = 'ELSE'">
[teal]<!-- figure out which if statement this else belongs to, then determine whether to output, or skip the else block -->[/teal]
<xsl:variable name="prevIfNode" select="$mergeData//docpro-print-entry/dataset/condition[substring-after($curNode, '<<ELSE>>')]"/>
<xsl:choose>
[teal]<!-- previous if statement evaluated to TRUE, so skip else block -->[/teal]
<xsl:when test="$prevIfNode = 'TRUE'">
<xsl:variable name="endNodeText" select="concat('<<ENDIF>>', $prevIfNode/@ref)"/>
<xsl:apply-templates select="following::node()[$endNodeText]"/>
</xsl:when>
[teal]<!-- previous if statement evaluated to FALSE, so output else block -->[/teal]
<xsl:otherwise>
[teal]<!-- don't output anything, & continue -->[/teal]
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="$curNode/@eval = 'END'">
[teal]<!-- don't output anything, & continue -->[/teal]
</xsl:when>
<xsl:otherwise>
<xsl:variable name="curIfNode" select="$mergeData//docpro-print-entry/dataset/condition[@ref = $curNode]"/>
<xsl:choose>
[teal]<!-- condition evaluates to true -->[/teal]
<xsl:when test="$curIfNode = 'TRUE'">
</xsl:when>
[teal]<!-- condition evaluates to false -->[/teal]
<xsl:otherwise>
<xsl:variable name="elseNodeText" select="concat('<<ELSE>>', $curNode/@ref)"/>
<xsl:apply-templates select="following::node()[$elseNodeText]"/>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:template>