select attributes in for-each problem

C

Chris

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

David Carlisle

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
 

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

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top