[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] recursion
Problem: I have an XML file that has notes mixed up with comments. I want to move the notes from current location to Notes element. There could be 0 to 10 notes. Solution: I will first copy notes found in span[@class='x'] from current location to Notes. With a second XSLT I will delete the unwanted ones. <xsl:variable name="notes" select="ancestor::Lexicon_Entry//LEXMeanings[1]//LEXSense[@LanguageCode='pt'] //span[@class='x']"/> Recursive code XSLT 2.0: <xsl:template name="get_note"> <xsl:param name="notes" select="."/> <xsl:param name="number" ><xsl:value-of select="."/></xsl:param> number /<xsl:value-of select="$number"/>/ notes[number] /<xsl:value-of select="$notes[$number]"/>/ notes /<xsl:value-of select="$notes"/>/ <xsl:choose> <xsl:when test="exists($notes[$number])"> <xsl:element name="note"> <xsl:attribute name="Caller"><xsl:value-of select="$number"/></xsl:attribute> <xsl:attribute name="LanguageCode">pt</xsl:attribute> <xsl:element name="Content"> <xsl:copy-of select="$notes[$number]"/> </xsl:element> </xsl:element> <xsl:call-template name="get_note"> <xsl:with-param name="notes" select="$notes"/> <xsl:with-param name="number"><xsl:value-of select="$number + 1"/></xsl:with-param> </xsl:call-template> </xsl:when> <xsl:otherwise> zzzzzzzz <!-- end --> </xsl:otherwise> </xsl:choose> </xsl:template> This works fine for 0 or 1 notes but when 2 or more are found it goes into an endless loop. Here is output with debugging code showing values <Note Caller="1" LanguageCode="en"> <References/> <Content>There are no doubt certain subtle differences of meaning in these terms, especially in their connotations, but it is not possible to specify the difference on the basis of existing contexts.</Content> </Note> <Note Caller="1" LanguageCode="pt"> <Content> <span class="x">2 Com certeza existem sutis diferenC'as de significado entre esses termos, especialmente em termos conotativos, mas nC#o C) possC-vel determinar isso com base nos contextos disponC-veis. </span></Content></Note> <note Caller="2" LanguageCode="pt"><Content><span class="x">3 Em Mt 5.21, <span lang="gk">N:Oa=7ON9O</span> se refere, provavelmente, a um tribunal local. </span></Content></note> number /3/ notes[number] /2 Com certeza existem sutis diferenC'as de significado entre esses termos, especialmente em termos conotativos, mas nC#o C) possC-vel determinar isso com base nos contextos disponC-veis. 3 Em Mt 5.21, N:Oa=7ON9O se refere, provavelmente, a um tribunal local. / notes /2 Com certeza existem sutis diferenC'as de significado entre esses termos, especialmente em termos conotativos, mas nC#o C) possC-vel determinar isso com base nos contextos disponC-veis. 3 Em Mt 5.21, N:Oa=7ON9O se refere, provavelmente, a um tribunal local. / so when $number is 3, $notes[$number] is the same as $notes but $notes[3] is the empty set. I have verified that $number is actually an integer. In this example there are two notes. The first note starts with 2 Com ... and the second note starts with 3 Em ... This puts me in an endless loop as it always finds something in $notes[$number] Jim Albright 704-562-1529 unlimited cell Wycliffe Bible Translators
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|