select attributes in for-each problem

Discussion in 'XML' started by Chris, Mar 31, 2005.

  1. Chris

    Chris Guest

    Hi,

    I just would like to iterate through some attributes of a tag
    (Section). Sometimes I only need one attribute and sometimes I need
    all attributes.
    In a xsl:param I declare the attribute name for the selection. So it's
    no problem if I only search for one attribute. But what can I declare
    in the same parameter when I need all attributes? As an expression I
    could write @* for all attributes. But I can't put that sign as value
    in the parameter -> Path Error.

    I appreciate any help!


    XML-File:
    ----------
    <Main>
    <Section id='basic'/>
    <Section id='test'/>
    <Section id='test2'/>
    </Main>




    XSL-File:
    ----------
    <xsl:template match="Main">
    <xsl:param name="searchID" select="'basic'"/>

    <!-- For all attributes -> I can't set @* as parameter value
    <xsl:for-each select="Section[@id=@*]">
    -->

    <!-- For only one attribute -->
    <xsl:for-each select="Section[@id=$searchID]">
    <b>
    <xsl:value-of select="@id" />
    </b>
    <br/>
    </xsl:for-each>

    </xsl:template>
     
    Chris, Mar 31, 2005
    #1
    1. Advertising

  2. in the same parameter when I need all attributes? As an expression I
    could write @* for all attributes. But I can't put that sign as value
    in the parameter -> Path Error.

    the select attribute of with-param takes an arbitrary XPath expression
    so you can use @* here.

    However your posting didn't suggest using @* in with-param but in teh
    expression

    xsl:for-each select="Section[@id=@*]

    That's legal but not what you meant as the [@id=@*] predicate is the
    same as the predicate [@id] and just tests if there is an id attribute.
    If there is one then it will be selected by both @id and @* so
    the test will be true as one value of the nodes selected by @id will be
    equal to one value of the nodes selected by @*.

    David
     
    David Carlisle, Mar 31, 2005
    #2
    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. John Blair
    Replies:
    1
    Views:
    421
    Eliyahu Goldin
    Aug 3, 2005
  2. Tjerk Wolterink

    xsl:for-each for each 3 elements problem

    Tjerk Wolterink, Nov 3, 2004, in forum: XML
    Replies:
    3
    Views:
    441
    Tjerk Wolterink
    Nov 3, 2004
  3. Pat Maddox
    Replies:
    6
    Views:
    161
    Marcin Mielżyński
    Jan 20, 2006
  4. Igor Nn
    Replies:
    7
    Views:
    445
    Johnny Morrice
    May 28, 2011
  5. palmiere
    Replies:
    1
    Views:
    431
    Erwin Moller
    Feb 9, 2004
Loading...

Share This Page