XSLT with output files

B

bbembi_de

Hello everyone,

I have a problem with a xsl transformation.

I have a input file like this:

<root>
<element name="element1">
<group name="111" />
<group name="222" />
</element>
<element name="element2">
<group name="111" />
<group name="333" />
<group name="444" />
</element>
</root>

Now I want a output file for every group. the output file should be
like this:

111.txt:
element1
element2

222.txt
element1
element2

333.txt
element3

and so on...

I use xslt 2.0 with saxon.
I know I have to write every output file at once. But how?

In my current solution I only get one output line each file:

....
<xsl:template match="/">
<xsl:for-each-group select="root/element/group" group-by="name">
<xsl:result-document href="{name}.xml">
<xsl:call-template name="CodeImplTemp"/>
</xsl:result-document>
</xsl:for-each-group>
....

<xsl:template name="CodeImplTemp">
<xsl:value-of select="../name"/>
</xsl:template>

Thanks
bye bembi
 
M

Martin Honnen

I have a input file like this:

<root>
<element name="element1">
<group name="111" />
<group name="222" />
</element>
<element name="element2">
<group name="111" />
<group name="333" />
<group name="444" />
</element>
</root>

Now I want a output file for every group. the output file should be
like this:

111.txt:
element1
element2

222.txt
element1
element2

But there is only one <group name="222"> as a child of <element
name="element1"> so I am not sure I understand where the element2 in
222.txt comes from.
333.txt
element3

and so on...

I use xslt 2.0 with saxon.
I know I have to write every output file at once. But how?

In my current solution I only get one output line each file:

...
<xsl:template match="/">
<xsl:for-each-group select="root/element/group" group-by="name">
<xsl:result-document href="{name}.xml">

<xsl:result-document href="{current-grouping-key()}.txt">
<xsl:apply-templates select="current-group()"/>
</xsl:result-document>
</xsl:for-each-group>
</xsl:template>


<xsl:template match="group">
<xsl:value-of select="../@name"/>
<xsl:if test="position() != last()">
<xsl:text>
</xsl:text>
</xsl:if>
</xsl:template>
 
B

bbembi_de

But there is only one <group name="222"> as a child of <element
name="element1"> so I am not sure I understand where the element2 in
222.txt comes from.






<xsl:result-document href="{current-grouping-key()}.txt">
<xsl:apply-templates select="current-group()"/>
</xsl:result-document>
</xsl:for-each-group>
</xsl:template>

<xsl:template match="group">
<xsl:value-of select="../@name"/>
<xsl:if test="position() != last()">
<xsl:text>
</xsl:text>
</xsl:if>
</xsl:template>

Oh, OK sorry my mistake.
It should be only element1 in 222.txt.

bye bembi
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top