I have written an XSL-file, that reads some filenames from the source file and uses this filenames, to split another file (which is opened in the XSL-file via the document() function). The filenames are used to create several output files and certain parts of the loaded file are written to these output files.
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsd="http://www.w3.org/2001/XMLSchema-instance">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="Root">
<xsl:apply-templates select="//Link"/>
</xsl:template>
<xsl:template match="Link">
<xsl:result-document href="{@url}" method="xml">
<xsl:apply-templates select="document('Input.xml')//Node"/>
</xsl:result-document>
</xsl:template>
<xsl:template match="Node">
<xsl:copy-of select="."/>
<xsl:if test="following-sibling::*[1][self::NextPart]">
<!-- write some test node -->
<xsl:element name="FoundNextPart"/>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
The sourcefile looks something like this
<Root>
<SomeNode>
<Link url="part_0.xml"/>
<Link url="part_1.xml"/>
<Link url="part_2.xml"/>
</SomeNode>
</Root>
The Input.xml file will have a structure like this
<Root>
<Node>
<PartContent>
<ImportantContent>0</ImportantContent>
</PartContent>
</Node>
<Node>
<PartContent>
<ImportantContent>0</ImportantContent>
</PartContent>
</Node>
<NextPart/>
<Node>
<PartContent>
<ImportantContent>1</ImportantContent>
</PartContent>
</Node>
<Node>
<PartContent>
<ImportantContent>1</ImportantContent>
</PartContent>
</Node>
<NextPart/>
</Root>
My problem is now with the
<xsl:template match="Node">
I want to copy the content of the Input.xml up to the first appearance of the
<NextPart/>
node. Then I want to somehow break out of the current nodeset (//Node of the Input.xml) and continue with the next //Link. But for this next Link (file) I want to copy the content of the Input.xml between the first and the second appearance of the
<NextPart/>
node.
I'm not sure if this is feasible in any way. Also I'm not sure if my approach can be used for this. I've read something like using
<xsl:call-template name="copy">
to use the following-sibling of the current node as a parameter. But anyway I have to pass the current count of the
<NextPart/>
so that I know, which content to copy!?