XSL for All Values for All Nodes

A

Al Hatch

I have an XML file of the form:

<AAA >
<BBB>0001</BBB>
<CCC>
<DDD>0121</DDD>
</CCC>
<DDD>
<EEE>0152</EEE>
<FFF>0032</FFF>
</DDD>
<GGG>0444</GGG>
</AAA>

What I want is

<COL>0001</COL >
<COL>0121</COL >
<COL>0152</COL >
<COL>0032</COL >
<COL>0444</COL >

What I get is

<COL>
0001

0121


0152
0032

0444
<COL>

using this Transform

<xsl:template match = "/" >
<xsl:for-each select = "/" >
<xsl:text ><COL></xsl:text>
<xsl:value-of select = "." />
<xsl:text ><COL></xsl:text>
<xsl:text >
</xsl:text>
</xsl:for-each>
</xsl:template>

Shouldn't this XSL just loop for each value? And where do all those extra CRs
come from? The nodes without attributes?
 
A

Al Hatch

I think you want
<xsl:for-each select="//text()">

That helps, but I still get sequences of blanks

<COL></COL>

for nodes that have no attribute.

//@* and //attribute* don't help, they also return those blanks.

How do I restrict my output to nodes that have attributes?
 
J

Johannes Koch

Al said:
I have an XML file of the form:

<AAA >
<BBB>0001</BBB>
<CCC>
<DDD>0121</DDD>
</CCC>
<DDD>
<EEE>0152</EEE>
<FFF>0032</FFF>
</DDD>
<GGG>0444</GGG>
</AAA>

What I want is

<COL>0001</COL >
<COL>0121</COL >
<COL>0152</COL >
<COL>0032</COL >
<COL>0444</COL >

Not tested:

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

<xsl:template match="*[not(*)]">
<COL>
<xsl:apply-templates/>
</COL>
</xsl:template>

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

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,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top