XSLT模板中的轴匹配
我想要这样的模板匹配:XSLT模板中的轴匹配,xslt,xpath,axes,Xslt,Xpath,Axes,我想要这样的模板匹配: <xsl:template match="//content[parent::(@type='async')]"> <table> <thead> <xsl:apply-templates select="row[@type='header']" /> </thead> <tbody> <xsl:apply-templates select="/row[@type='d
<xsl:template match="//content[parent::(@type='async')]">
<table>
<thead>
<xsl:apply-templates select="row[@type='header']" />
</thead>
<tbody>
<xsl:apply-templates select="/row[@type='data']" />
</tbody>
</table>
</xsl:template>
使用此XML:
<document type="async">
<content>
<!-- Some rows with types -->
</content>
</document>
我的问题是
,我如何使其工作?这里有一种方法:
//content[parent::*/@type='async']
可缩短为:
//content[../@type='async']
还有一个:
//*[@type='async']/content
注意:一般来说,如果您知道元素的名称(
document
,在本例中为),则最好是显式的,避免使用*
符号,如果您知道确切的路径,尤其是/
符号
具体地说,在匹配模式中,前导的/
是多余的,因为如果(且仅当)模式在遍历输入树的过程中匹配,模板将自动应用。在模式中,任何前导的/
也可以删除。@MartinHonnen谢谢,我太专注于一般的XPath方面,忽略了问题的具体上下文。你也可以编写match=“*[@type='async']]]/content”
@MichaelKay,我想我已经写了。需要一对新的规范。既然语法无效,我们怎么知道你想要它做什么?我们不能期望通过阅读一个不符合要求的程序来解决您的要求。