开发者

How to match an element value to an attribute value in a sub-node of a sibling node

Given an XML document with a number of elements that look like this:

<column>
  <question>
  ...
  </question>
  <question>
    <description>Colour<开发者_如何转开发/description>
    <choices>
      <choice value="">[Select colour]</choice>
      <choice value="id01">Red</choice>
      <choice value="id02">Green</choice>
      <choice value="id03">Blue</choice>
      <choice value="id04">Yellow</choice>
    </choices>
    <chosen>id02</chosen>
  </question>
</column>

...and (part of) an XSL transformation that looks like this:

<xsl:for-each select="column/question">
      <xsl:value-of select="description"/>
      <xsl:value-of select="chosen"/>
      <xsl:value-of select="choices/choice[@value='id02']"/>    
</xsl:for-each>

...what's the best or easiest way to return the "Green" value without hard-coding this? I'm new at this; it must be really easy, but I can't figure out how. The last "value-of select" in the XSL has a hard-coded attribute filter, but what I really want is to compare it to the value of for each in my doc, something like where "choices/choice[@value=/question/chosen]"...but then working :-)

Again, I'm sure this is really easy, but hours of Googling aren't getting me anywhere. Thanks for your help and patience.


Something like...

choices/choice[@value=../../chosen]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜