XSL for All Values for All Nodes

Discussion in 'XML' started by Al Hatch, Jun 5, 2006.

  1. Al Hatch

    Al Hatch Guest

    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?
     
    Al Hatch, Jun 5, 2006
    #1
    1. Advertising

  2. 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/
     
    Martin Honnen, Jun 5, 2006
    #2
    1. Advertising

  3. Al Hatch

    Al Hatch Guest

    On Mon, 5 Jun 2006 10:30:38 -0700, Martin Honnen wrote
    (in article <44846a43$0$4500$-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?
     
    Al Hatch, Jun 5, 2006
    #3
  4. 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)
     
    Johannes Koch, Jun 5, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. asd
    Replies:
    3
    Views:
    452
    Arnaud Berger
    May 23, 2005
  2. gavnosis
    Replies:
    0
    Views:
    538
    gavnosis
    Aug 2, 2003
  3. Timo Nentwig

    selecting nodes between other nodes

    Timo Nentwig, Jun 16, 2004, in forum: XML
    Replies:
    1
    Views:
    428
    Patrick TJ McPhee
    Jun 17, 2004
  4. Tjerk Wolterink
    Replies:
    3
    Views:
    478
    Marrow
    Oct 22, 2004
  5. Replies:
    1
    Views:
    3,653
    A. Bolmarcich
    May 27, 2005
Loading...

Share This Page