gpt4 book ai didi

xml - 如何根据xslt中以 "Heading"开头的属性值选择xml元素?

转载 作者:数据小太阳 更新时间:2023-10-29 01:44:38 24 4
gpt4 key购买 nike

每当我发现其属性值以“标题”开头的 xml 元素匹配时,我想调用我自己的 xsl 模板。我如何在 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>

上面的 XSLT,除非您确实在它说的地方添加了您自己的代码,否则将从 XML 中删除所有数学运算 w:pStyle 元素。

关于xml - 如何根据xslt中以 "Heading"开头的属性值选择xml元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6895023/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com