可以做点什么:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:param name="pPath1" select="'/books/book/title'"/>
<xsl:param name="pPath2" select="'/books/book/description'"/>
<xsl:key name="kElemByPath" match="*"
use="concat('/', name(ancestor-or-self::*[last()])
,'/', name(ancestor-or-self::*[last()-1])
,'/', name(ancestor-or-self::*[last()-2])
)"/>
<xsl:template match="/">
<xsl:copy-of select="key('kElemByPath', $pPath1)"/>
==========
<xsl:text/>
<xsl:copy-of select="key('kElemByPath', $pPath2)"/>
</xsl:template>
</xsl:stylesheet>
当此转换应用于以下 XML 文档时:
<books>
<book isbn="1590593049">
<title>Extending Flash MX 2004</title>
<description>
Using javascript alongwith actionscript 3.0 and mxml.</description>
</book>
<book isbn="0132149184">
<title>Java Software Solutions</title>
<description>
Complete book full of case studies on business solutions and design concepts while building mission critical
business applications.
</description>
</book>
</books>
产生了想要的正确结果:
<title>Extending Flash MX 2004</title>
<title>Java Software Solutions</title>
==========
<description>
Using javascript alongwith actionscript 3.0 and mxml.</description>
<description>
Complete book full of case studies on business solutions and design concepts while building mission critical
business applications.
</description>
如果您知道“路径”中的最大定位步骤数,则可以定义类似于此示例的键。位置步数较少的表达式必须以必要数量的斜杠结尾。