xsl question

H

Hakan

Hello,

Ik have a dynamic XML document of which the tags may change.
I want to translate this XML document to a certain format. The
structure of the XML document could be as follows:

<a>
<b>
<c>
<c1>hello1</c1>
<c2>hello2</c2>
<c3>hello3</c3>
<c4>hello4</c4>
<c5>hello5</c5>
<c6>hello6</c6>
</c>

<c>
<d>
<d1>hellod1</d1>
<e>
<e1>helloe1</e1>
<e2>helloe1</e2>
<e3>helloe1</e3>
<e4>helloe1</e4>
</e>
</d>

</c>
</a>

=============
From the children of tag b, the subtrees should be translated
recurisevely like:

b:
c:
c1: hello1
c2: hello2
c3: hello3</c3>
c4: hello4</c4>
c5: hello5</c5>
c6: hello6</c6>

c:
d:
d1: hellod1

e:
e1: helloe1
e2: helloe1
e3: helloe1
e4: helloe1

the labels a, b, c, d, e, e1 et cetera are sample labels. These labels
could change everytime. What I need is code to translate these type of
XML documents in such a format.

Can anyone give me some advice?
 
J

Joris Gillis

Hi,

Tempore 13:50:13 said:
From the children of tag b, the subtrees should be translated
recurisevely

you'll need some code like this:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:eek:utput method="text"/>

<xsl:template match="*">
<xsl:for-each select="../ancestor::*"><xsl:text> </xsl:text></xsl:for-each>
<xsl:value-of select="name()"/>: <xsl:value-of select="text()"/>
<xsl:text>
</xsl:text>
<xsl:apply-templates select="*"/>
</xsl:template>

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

</xsl:stylesheet>


regards,
 

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
474,001
Messages
2,570,250
Members
46,848
Latest member
Graciela Mitchell

Latest Threads

Top