[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Recursion
In general, keeping book of the files that you have already seen is a
good idea. But you should use a sequence of file names, or better of
absolute URIs.
Then its advisable to use parameter tunneling, just in case that there are intermediate elements between xml1 and includes. And it is usually a good idea to use XSLTs template matching / apply-templates mechanism instead of for-each/call-template (particularly if theres other content on the same level as 'includes'. Gerrit
<xsl:output method="xml" indent="yes" /> <!-- If there is other content than xml1 and includes, reproduce it with an Identity template: <xsl:template match="@* | *"> <xsl:copy> <xsl:apply-templates select="@* | node()" mode="#current"/> </xsl:copy> </xsl:template> <xsl:template match="xml1"> <!-- Use tunneling (particularly useful when there are intermediate elements): --> <xsl:param name="seen" as="xs:string*" tunnel="yes"/> <xsl:copy> <xsl:attribute name="xml:base" select="base-uri(.)" /> <xsl:apply-templates> <xsl:with-param name="seen" select="($seen, base-uri(.))" tunnel="yes" /> </xsl:apply-templates> </xsl:copy> </xsl:template> <!-- Use template matching instead of for-each and call-template: --> <xsl:template match="includes" as="element(*)?"> <xsl:param name="seen" as="xs:string*" tunnel="yes"/> <xsl:variable name="file" select="document(.)" as="document-node(element(*))" /> <xsl:choose> <xsl:when test="base-uri($file) = $seen"> <xsl:message>Already seen: <xsl:sequence select="base-uri($file)" /> </xsl:message> </xsl:when> <xsl:otherwise> <xsl:apply-templates select="$file" /> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet> Sample output (added some bogus content to some files and renamed file1.1.1xml to file1.1.1.xml): $ saxon -xsl:test.xsl main.xml Already seen: file:/C:/cygwin/home/gerrit/XSLT-trivia/mulberry-xsl-list/2012-05-28_vasucv@xxxxxxxxx/file1.xml <?xml version="1.0" encoding="UTF-8"?> <xml1 xml:base="file:/C:/cygwin/home/gerrit/XSLT-trivia/mulberry-xsl-list/2012-05-28_vasucv@xxxxxxxxx/main.xml"> <xml1 xml:base="file:/C:/cygwin/home/gerrit/XSLT-trivia/mulberry-xsl-list/2012-05-28_vasucv@xxxxxxxxx/file1.xml"> <xml1 xml:base="file:/C:/cygwin/home/gerrit/XSLT-trivia/mulberry-xsl-list/2012-05-28_vasucv@xxxxxxxxx/file1.1.xml"> <xml1 xml:base="file:/C:/cygwin/home/gerrit/XSLT-trivia/mulberry-xsl-list/2012-05-28_vasucv@xxxxxxxxx/file1.1.1.xml">1.1.1 </xml1> </xml1> <xml1 xml:base="file:/C:/cygwin/home/gerrit/XSLT-trivia/mulberry-xsl-list/2012-05-28_vasucv@xxxxxxxxx/file1.2.xml">1.2 </xml1> </xml1> <xml1 xml:base="file:/C:/cygwin/home/gerrit/XSLT-trivia/mulberry-xsl-list/2012-05-28_vasucv@xxxxxxxxx/file2.xml"> <xml1 xml:base="file:/C:/cygwin/home/gerrit/XSLT-trivia/mulberry-xsl-list/2012-05-28_vasucv@xxxxxxxxx/file2.1.xml">2.1 </xml1> <xml1 xml:base="file:/C:/cygwin/home/gerrit/XSLT-trivia/mulberry-xsl-list/2012-05-28_vasucv@xxxxxxxxx/file2.2.xml">2.2 </xml1> </xml1> </xml1> On 2012-05-28 12:58, Vasu Chakkera wrote: Guys,
Registergericht / Commercial Register: Amtsgericht Leipzig Registernummer / Registration Number: HRB 24930 Geschdftsf|hrer: Gerrit Imsieke, Svea Jelonek, Thomas Schmidt, Dr. Reinhard Vvckler
|
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
|