Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XSL for All Values for All Nodes

Reply
Thread Tools

XSL for All Values for All Nodes

 
 
Al Hatch
Guest
Posts: n/a
 
      06-05-2006
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?

 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      06-05-2006


Al Hatch wrote:

> <xsl:template match = "/" >
> <xsl:for-each select = "/" >


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

--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
 
 
 
Al Hatch
Guest
Posts: n/a
 
      06-05-2006
On Mon, 5 Jun 2006 10:30:38 -0700, Martin Honnen wrote
(in article <44846a43$0$4500$(E-Mail Removed)-online.net>):

> 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?


 
Reply With Quote
 
Johannes Koch
Guest
Posts: n/a
 
      06-05-2006
Al Hatch wrote:
> 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>

--
Johannes Koch
Spem in alium nunquam habui praeter in te, Deus Israel.
(Thomas Tallis, 40-part motet)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
XSL Question tp xsl:for-each and xsl:variable schaf@2wire.ch XML 1 05-27-2005 09:25 PM
Text nodes and element nodes query asd Java 3 05-23-2005 10:01 AM
XSL: XPath copying all nodes that are not in a namespace Tjerk Wolterink XML 3 10-21-2004 11:17 PM
selecting nodes between other nodes Timo Nentwig XML 1 06-17-2004 04:54 AM
Reality check: Is it sensible to link XML nodes to other XML nodes in the same file? gavnosis XML 0 08-02-2003 08:22 AM



Advertisments