XSLT - using attribute values in elements?

Status
Not open for further replies.

Twit

Ars Praefectus
3,036
I'm transforming some data which has attributes containing xpaths to...well, stuff. Those xpaths are being output to HTML in placeholders 'n such - all that's fine. The trouble I have is in using those paths during the transformation.

For example, let's say one of those xpaths points to data within the xml being transformed. From my template I want to output the value resolved from the xpath, not the xpath itself. If I did [xsl:select value="@xpath"/] I wouldn't get the data, I'd get the xpath as text. The only thing I could think of was to bung some javascript in there, and then I basically use something like [xsl:select value="userfn:getDataValue[@xpath)"/].

Now, what if that xpath pointed me not to a single item of data, but to a node list? In other words, what if I wanted to do something like [xsl:for-each select="@xpath"]. Remember - I don't want to find the @xpath attribute in the current context - I want to use the value within @xpath to find a node list.

Things I've tried:

- putting the value of @xpath into an [xsl] and using $xpath in the select. Tells me it should contain a nodeList.

- Another function that takes the value, performs a selectNodes on /, and returns the result. Parser doesn't seem to like my function returning nodeLists though.

Anyone have a simple and neat solution to this?

Edit - had to square bracket those tags cause they weren't being rendered. You know what I mean though right?

[This message was edited by Twit on March 05, 2002 at 23:36.]
 

Twit

Ars Praefectus
3,036
In case anyone was paying any attention to this, I managed to achieve what I was after using something like:

code:<HR>
Code:
<xsl:template match="repeatingGroup">
  <xsl:variable name="childNodes" select="*"/>
  <xsl:value-of select="userfn:putmxpath(string(@xpath))"/>
  <span id="repeatingGroup" xpath="{@xpath}">
    <xsl:for-each select="userfn:getNodes(/,.)">
      <xsl:value-of select="userfn:putmindex(position())"/>
      <xsl:apply-templates select="$childNodes"/>
    </xsl:for-each>
  </span>
  <xsl:value-of select="userfn:putmxpath('')"/>
  <xsl:value-of select="userfn:putmindex('0')"/>
</xsl:template>

...which applies templates in one context for the number of times in a different context (taken from an xpath in an attribute) and knowing which index position it lives at.
 
Status
Not open for further replies.