每当我发现xml元素的匹配时,我想调用我自己的xsl模板,其属性值以“Heading”开头.如何在Xslt中进行此查询.
例如:
- <w:p>
- <w:pPr>
- <w:pStyle w:val="Heading2"/>
- </w:pPr>
- </w:p>
- <w:p>
- <w:pPr>
- <w:pStyle w:val="Heading1"/>
- </w:pPr>
- </w:p>
- <w:p>
- <w:pPr>
- <w:pStyle w:val="Heading2"/>
- </w:pPr>
- </w:p>
- <w:p>
- <w:pPr>
- <w:pStyle w:val="ListParagraph"/>
- </w:pPr>
- </w:p>
- <w:p>
- <w:pPr>
- <w:pStyle w:val="commentText"/>
- </w:pPr>
- </w:p>
所以,我想查询w:pStyle – > w:val仅以“标题”开头.
请帮我解决这个问题……
您可以通过使用XPath字符串函数来实现此目的
- <xsl:template match="w:pStyle[starts-with(@w:val,'Heading')]">
这简单地匹配所有w:pStyle节点,其中w:val属性以单词Heading开头.然后,您可以将自己的代码放在此模板中.
以下是如何在XSLT标识转换中使用它的示例
- <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:w="http://mynamespace.com">
- <xsl:output method="xml" indent="yes"/>
- <xsl:template match="w:pStyle[starts-with(@w:val,'Heading')]">
- <!-- Your code here -->
- </xsl:template>
- <xsl:template match="@*|node()">
- <xsl:copy>
- <xsl:apply-templates select="@*|node()"/>
- </xsl:copy>
- </xsl:template>
- </xsl:stylesheet>