Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > select attributes in for-each problem

Reply
Thread Tools

select attributes in for-each problem

 
 
Chris
Guest
Posts: n/a
 
      03-31-2005
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 xslaram 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">
<xslaram 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>
 
Reply With Quote
 
 
 
 
David Carlisle
Guest
Posts: n/a
 
      03-31-2005

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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
attributes ala java annotations or .Net attributes? Kyle Schmitt Ruby 3 07-24-2007 07:48 PM
class attributes & data attributes james_027 Python 2 06-20-2007 03:12 PM
WebControl.Attributes.Add and custom attributes P4trykx ASP .Net 2 01-31-2007 04:33 PM
Parse reserved attributes as normal attributes Max XML 1 09-22-2006 12:04 PM
select of select box will select multiple in another box palmiere Javascript 1 02-09-2004 01:11 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57