Create tag names via XSL

C

Chris

I have the following XML:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<ORDERS>
<ORDER>
<ORDER_ID>123</ORDER_ID>
<X>a</X>
<X>e</X>
<X>f</X>
</ORDER>
<ORDER>
<ORDER_ID>124</ORDER_ID>
<X>a</X>
<X>b</X>
<X>c</X>
</ORDER>
</ORDERS>

Is it possible to create the following XML document via XSL?

<?xml version="1.0" encoding="ISO-8859-1" ?>
<ORDERS>
<ORDER>
<ORDER_ID>123</ORDER_ID>
<X1>a</X1>
<X2>e</X2>
<X3>f</X3>
</ORDER>
<ORDER>
<ORDER_ID>124</ORDER_ID>
<X1>a</X1>
<X2>b</X2>
<X3>c</X3>
</ORDER>
</ORDERS>

Any ideas?

Thanx in advance,

Chris
 
C

Chris

Additon: I know that there will bee a maximum of 32 x-entries in the
source document, the exact amount can vary, so there must be a
dynamically solution.

Chris
 
J

Janwillem Borleffs

Chris said:
Is it possible to create the following XML document via XSL?

xsl:copy-of can do this for you:

<ORDERS>
<xsl:copy-of select="descendant::*" />
</ORDERS>

Or didn't you mean to get an exact copy of the document?


JW
 
M

Martin Honnen

Chris said:
I have the following XML:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<ORDERS>
<ORDER>
<ORDER_ID>123</ORDER_ID>
<X>a</X>
<X>e</X>
<X>f</X>
</ORDER>
<ORDER>
<ORDER_ID>124</ORDER_ID>
<X>a</X>
<X>b</X>
<X>c</X>
</ORDER>
</ORDERS>

Is it possible to create the following XML document via XSL?

<?xml version="1.0" encoding="ISO-8859-1" ?>
<ORDERS>
<ORDER>
<ORDER_ID>123</ORDER_ID>
<X1>a</X1>
<X2>e</X2>
<X3>f</X3>
</ORDER>
<ORDER>
<ORDER_ID>124</ORDER_ID>
<X1>a</X1>
<X2>b</X2>
<X3>c</X3>
</ORDER>
</ORDERS>

Yes, one way to do it is

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

<xsl:eek:utput method="xml" encoding="ISO-8859-1" />

<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()" />
</xsl:copy>
</xsl:template>

<xsl:template match="X">
<xsl:element name="X{count(preceding-sibling::X) + 1}">
<xsl:apply-templates />
</xsl:element>
</xsl:template>

</xsl:stylesheet>
 

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,999
Messages
2,570,247
Members
46,844
Latest member
JudyGvh32

Latest Threads

Top