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. Advertisements

  2. I think you want
    <xsl:for-each select="//text()">
     
    Martin Honnen, Jun 5, 2006
    #2
    1. Advertisements

  3. Al Hatch

    Al Hatch Guest

    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. 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, Jun 5, 2006
    #4
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.