xml - 使用 xslt 循环遍历简单的 xml
问题描述
我有一条肥皂消息
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<id>0</id>
<id>1</id>
</soapenv:Body>
</soapenv:Envelope>
我想遍历 id 元素并检查当前元素的值是否 = 1 但我的 xslt 不起作用。
<xsl:template match="/">
<xsl:for-each select="node()">
<xsl:if test="current()/text='1'">
do something
</xsl:if>
</xsl:for-each>
</xsl:template>
有人可以指出我做错了什么并指导我如何进行吗?
编辑:我需要一些在 id 之一等于 1 时返回 true 的东西,否则返回 false 。
解决方案
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
exclude-result-prefixes="xs"
version="2.0">
<xsl:template match="soapenv:Envelope">
<xsl:for-each select="soapenv:Body">
<xsl:if test="id='1'">
do something
</xsl:if>
</xsl:for-each>
</xsl:template>
You may use like this
推荐阅读
- sql - 使用多个选择语句插入私有临时表
- python - 使用模数对数据进行分块的优雅方法?
- python - 如何在导入模块中模拟 pytest 全局变量
- spring - 如何仅通过配置禁用特定 url 的 spring 安全性?
- linux - Docker Compose 在容器的 /etc/hosts 中设置 Linux Docker 主机 IP 地址
- javascript - 为什么我的 API 请求在 javascript(Chrome 扩展程序)中被取消
- objective-c - NSUndoManager 和替换/跳过撤消步骤
- amazon-web-services - 如果给定 RDS DbiResourceId,我是否可以连接到任意 RDS 数据库实例?
- azure-logic-apps - 嵌套逻辑应用程序 - 从子级获取状态代码
- ruby-on-rails - 在 postgres 数据库中保存来自 Shopify API 的 GraphQL 查询