xsl-list
[Top] [All Lists]

Re: [xsl] Child Nodes Problem

2010-06-03 06:01:54
On 03/06/2010 11:46, Byomokesh Sahoo wrote:


  <xsl:variable name="delimiter" select="'&#9;'"/>
  <xsl:variable name="fieldNames" select="'yes'"/>

  <xsl:template match="/">

    <xsl:for-each select="//Product/child::*|//Product/self::*">

That is the same as //Product/(.|*) although do you really need to search the entire document with // for product, or is it always at the top of your file. Your code below does for-each starting from here so it appears to be expecting to llop over the children of product, so i suspect this line should be
<xsl:for-each select="//Product">



      <xsl:if test="$fieldNames = 'yes'">

        <xsl:if test="position() = 1 or position()&gt;1">
this test is always true as position() is always an integer greater than zero, for all documents.

          <xsl:for-each select="@*">
            <xsl:value-of select="name()"/>
this would list the names of the attributes (in an arbitrary order) but your sample input has no attributes
            <xsl:value-of select="$delimiter"/>

          </xsl:for-each>

          <xsl:for-each select="*">
            <xsl:value-of select="name()"/>

            <xsl:if test="position() != last()">
              <xsl:value-of select="$delimiter"/>
            </xsl:if>
          </xsl:for-each>
          <xsl:text>
        </xsl:text>
here you prpbably just want <xsl:text>&#10;</xsl:text>
to insert a newline rather than a newline and some indentation space copied from the stylesheet.
        </xsl:if>
      </xsl:if>
      <xsl:for-each select="@*">
        <xsl:value-of select="."/>
        <xsl:value-of select="$delimiter"/>
      </xsl:for-each>
again this would list any attributes if you had them.
      <xsl:for-each select="*">
        <xsl:value-of select="."/>
        <xsl:if test="position() != last()">
          <xsl:value-of select="$delimiter"/>
        </xsl:if>
      </xsl:for-each>
The above for-each (which was the xslt 1 way) can be more simply written as
<xsl:value-of select="*" separator="$delimiter"/>

      <xsl:text>
</xsl:text>
again just use ,xsl:text>&#10;</xsl:text> if you want to insert just a new line and no spaces.
    </xsl:for-each>
  </xsl:template>

David

________________________________________________________________________
The Numerical Algorithms Group Ltd is a company registered in England
and Wales with company number 1249803. The registered office is:
Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom.

This e-mail has been scanned for all viruses by Star. The service is
powered by MessageLabs. ________________________________________________________________________

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>