Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use xsl:document to create new output file(s)

Status
Not open for further replies.

chrislx

Programmer
Oct 17, 2003
32
0
0
US
Please anyone help me on creating a new output file using xsl:document.

I found the following example from book "XSLT 2nd Edition Programmer's Reference"

poem.xml
========
<poem>
<author>Rupert Brooke</author>
<date>1912</date>
<title>Song</title>
<stanza>
<line>And suddenly the wind comes soft,</line>
<line>And Spring is here again;</line>
<line>And the hawthorn quickens with buds of green</line>
<line>And my heart with buds of pain.</line>
</stanza>
<stanza>
<line>My heart all Winter lay so numb,</line>
<line>The earth so dead and frore,</line>
<line>That I never thought the Spring would come again</line>
<line>Or my heart wake any more.</line>
</stanza>
<stanza>
<line>But Winter's broken and earth has woken,</line>
<line>And the small birds cry again;</line>
<line>And the hawthorn hedge puts forth its buds,</line>
<line>And my heart puts forth its pain.</line>
</stanza>
</poem>

split.xsl
=========

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl=" version="1.1">
<xsl:template match="poem">
<poem>
<xsl:copy-of select="title"/>
<xsl:copy-of select="author"/>
<xsl:copy-of select="date"/>
<xsl:apply-templates select="stanza"/>
</poem>
</xsl:template>

<xsl:template match="stanza">
<xsl:variable name="file" select="concat('verse', position(), '.xml')"/>
<verse number="{position()}" href="{$file}"/>
<xsl:document href="{$file}">
<xsl:copy-of select="."/>
</xsl:document>
</xsl:template>
</xsl:stylesheet>

How and where are the following output files generated?

one principal output file:
<?xml version="1.0" encoding="utf-8" ?>
<poem>
<title>Song</title>
<author>Rupert Brooke</author>
<date>1912</date>
<verser number="1" href="versel1.xml"/>
<verser number="2" href="versel2.xml"/>
<verser number="3" href="versel3.xml"/>
</poem>

three further output files:
<?xml version="1.0" encoding="utf-8" ?>
<stanza>
<line>And suddenly the wind comes soft, </line>
<line>and spring is here again;</line>
<line>and the hawthorn quickens with buds of green</line>
<line>and my heart with buds of pain.</line>
</stanza>

Thanks in advance,

chrislx
 
What is it you want to know?
The files are genereted as a result of transforming the xml-file with the xsl-stylesheet. In the first part of the xsl, the direct outout, the result your parser will return, is generated. In the second part some external files are created using the <xsl:document> element.
Mind you, this element is NOT supported in xsl version 1.0 and most parsers, so even if it works on your machine, it probably will fail on any other.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top