xml - 如何处理 XSLT 中的处理指令
问题描述
我想使用XSLT 2.0
. 我已经解释了我使用以下示例。
输入:
<code>
<bigin>
<?codestuct a?>
<butic>
<a>a</a>
<a>b</a>
</butic>
<?codestuct c?>
<butic>
<a>a</a>
<a>b</a>
</butic>
</bigin>
<medium>
<?codestuct a?>
<super>
<p>para1</p>
</super>
<?codestuct b?>
<super>
<p>para2</p>
</super>
<?codestuct c?>
<super>
<p>para3</p>
</super>
</medium>
</code>
如果<super>
处理指令等于处理指令,我想要添加字符串<butic>
。
举个例子,
第一<super>
元素处理指令等于第一<butic>
处理指令。然后found
应该在输出中打印字符串。
但是第二个<super>
元素处理指令不等于任何<butic>
元素。
预期输出:
<output>
<extreme>Founded</extreme>
<extreme>Not Founded</extreme>
<extreme>Founded</extreme>
</output>
试过的代码:
<xsl:template match="medium">
<output>
<xsl:choose>
<xsl:when test="preceding-sibling::bigin/processing-instruction('codestuct') = super/processing-instruction('codestuct')">
<extreme>
<xsl:value-of select="'Founded'"/>
</extreme>
</xsl:when>
<xsl:otherwise>
<extreme>
<xsl:value-of select="'Not Founded'"/>
</extreme>
</xsl:otherwise>
</xsl:choose>
</output>
</xsl:template>
解决方案
目前尚不清楚您要比较什么以及这些元素是否重要,但是
<xsl:template match="code">
<output>
<xsl:apply-templates select="medium/processing-instruction()"/>
</output>
</xsl:template>
<xsl:template match="medium/processing-instruction()">
<extreme>Not found</extreme>
</xsl:template>
<xsl:template match="medium/processing-instruction()[some $pi in /code/bigin/processing-instruction() satisfies deep-equal(., $pi)]">
<extreme>Found</extreme>
</xsl:template>
给
<output>
<extreme>Found</extreme>
<extreme>Not found</extreme>
<extreme>Found</extreme>
</output>
推荐阅读
- docker - Go 应用程序在 Docker 中挂起
- select - 带参数的自定义 Select()
- bats-core - 如何使用蝙蝠测试`read -p`
- javascript - 处理“无法获取”错误
- vba - 在 VBA 中查找最早的日期
- javascript - 当十进制值诗句计数动画卡住
- java - Java:使用自定义注释的方法级授权检查
- ubuntu - 同时作为单独的用户运行服务 - Ubuntu 服务器 - Minecraft/OpenVPN
- amazon-web-services - 单独的 Dockerrun.aws.json 文件用于暂存和生产
- java - 如何使用通过 Java 传递的布尔值调用方法