This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: attribute


Hi,

><xsl:template match="temp">
><xsl:for-each select="item">
>...
></xsl:for-each>
></xsl:template>
>
>How can I reference an attribute of temp from within the for-each?
>I am saving the attribute to a variable outside of the for-each, is there a 
>better way?

Your XSLT above shows that 'item' is a child of 'temp', and your tree looks
like:

- temp
  +- @attr <-- the attribute you want
  +- item  <-- the current node within the xsl:for-each

Given this, you can see that to get from the 'item' element to the 'attr'
attribute, you need to go up to the 'temp' element (parent:: axis), and
then down again (attribute:: axis) to the 'attr' attribute:

  parent::temp/attribute::attr

Or, shorter:

  ../@attr

If the 'item' element hadn't been related as closely to the 'temp' element,
then setting the variable would have been the only way to do it.

I hope this helps,

Jeni

Jeni Tennison
http://www.jenitennison.com/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]