0

我正在尝试<abc-value>abc</abc-value>从当前节点获取其他子节点元素的值。

例子:

<root>
  <child1>
     <abc-value>abc</abc-value>
  </child>
  <child2>
     <attribute name=def>def</def-value>
  </child2>
</root>

XSL:

<xsl:template name="child2" match="attribute">
   child1 value is: <xsl:value-of select="../abc-value"/>
   child2 value is: <xsl:value-of select="current()"/>
</xsl:template> 

我要做的就是,从 child2 模板匹配,我调用 child1 元素的值<abc-value>abc</abc-value>

预计出来:

Child1 值为:abc

Child2 值为:def

4

1 回答 1

3
<xsl:template name="child2" match="attribute">
   child1 value is: <xsl:value-of select="../../child1/abc-value" />
   child2 value is: <xsl:value-of select="." />
</xsl:template> 

Update: based on the edit to your question:

  • The template now matches the <attribute> element.
  • Since the current node for the template (the <attribute> element) is deeper than before, the select expression for the child1 value is changed to use an additional ../.
于 2013-10-01T02:34:32.583 回答