select attributes in for-each problem

Chris (archive)

Usenet Archive
Joined
Jan 11, 2000
Messages
1,243
Reaction score
0
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>
 

David Carlisle

Usenet Archive
Joined
Jan 5, 2000
Messages
609
Reaction score
0
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
548,049
Messages
3,104,245
Members
248,133
Latest member
DujonT

Latest Threads

Top