xsl-list
[Top] [All Lists]

Re: exsl:document help

2004-09-30 00:12:49
Hi Greg,

 <xsl:template match="CCC">
   <exsl:document href="{../../@id}" method="text">
     <xsl:value-of select="."/>
   </exsl:document>
 </xsl:template>
That means: for every CCC element, create a document. So the processor will create a file 'a2' containing 'c2', and then immediately overwrite it with a file 'a2' containing 'c3'.
In fact you want to create a document for every AAA element:

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
               xmlns:exsl="http://exslt.org/common";
               extension-element-prefixes="exsl"
               version="1.0">

 <xsl:template match="/source">
   <xsl:apply-templates select="AAA"/>
 </xsl:template>

 <xsl:template match="AAA">
   <exsl:document href="{(_at_)id}" method="text">
     <xsl:apply-templates select="BBB/CCC"/>
   </exsl:document>
 </xsl:template>

 <xsl:template match="CCC">
   <xsl:value-of select="."/>
   <xsl:text>&#xA;</xsl:text>
 </xsl:template>

</xsl:stylesheet>

Cheers,
Anton


Greg Schafer wrote:

Hello

Relative newbie here using xsltproc.

Given this xml:


<?xml version='1.0' encoding="ISO-8859-1"?>
<source>
 <AAA id="a1">
   <BBB>
     <CCC>c1</CCC>
   </BBB>
 </AAA>
 <AAA id="a2">
   <BBB>
     <CCC>c2</CCC>
   </BBB>
   <BBB>
     <CCC>c3</CCC>
   </BBB>
 </AAA>
</source>


This XSLT sylesheet _almost_ achieves the desired goal:


<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
               xmlns:exsl="http://exslt.org/common";
               extension-element-prefixes="exsl"
               version="1.0">

 <xsl:template match="/">
   <xsl:apply-templates select="//BBB"/>
 </xsl:template>

 <xsl:template match="CCC">
   <exsl:document href="{../../@id}" method="text">
     <xsl:value-of select="."/>
   </exsl:document>
 </xsl:template>

</xsl:stylesheet>


Document `a1' is created properly. But document `a2' contains only `c3' when
I need it to contain:

c2
c3

Can anyone point me in the right direction?
Thanks in advance.

Greg



<Prev in Thread] Current Thread [Next in Thread>