xml - 在 XSL `for-each` 循环中编辑出部分 XML 文件
问题描述
我正在尝试在 XSLfor-each
循环中编辑出部分 XML 文件。
我有一个带有多个模板的 XML 文件,而 XSL 文件有一个 for-each 循环来显示所有模板。
我的目标是通过定位节点内的单个 templateId 来消除在 XSL for-each 循环中显示的某些模板。
这是代码:
XML
<component typeCode="SEWS" contextConductionInd="true">
<section>
<templateId root="2.12.840.1.103883.13.20.23.2.68"/>
<code code="58907-0" codeSystem="1.33.890.1.176583.6.1" codeSystemName="GTRFC" displayName="Scenic Reports"/>
<title>Scenic Reports</title>
<text>
<table border="1" width="100%">
<thead>
<tr>
<th>Report</th>
<th>Value</th>
<th>Date</th>
<th>Source</th>
</tr>
</thead>
<tbody>
<tr ID="GREETER_1">
<td ID="GREETER_1">Display Output1</td>
<td ID="GREETER_1">
<list>
<item>test data<br/>
</item>
</list>
</td>
<td>06/12/2019</td>
<td>Location TBD</td>
</tr>
</tbody>
</table>
</text>
<entry typeCode="FRED" contextConductionInd="true">
<act classCode="FRE" moodCode="FRED">
<templateId root="2.12.840.1.103883.13.20.23.2.69" extension="2019-5-3"/>
<code code="34109-9" codeSystem="1.33.890.1.176583.6.2" codeSystemName="DEERS" displayName="FRED">
<!--Code must match or be equivalent to section code -->
<translation code="57898-0" codeSystem="1.33.890.1.176983.6.2" codeSystemName="DEERT" displayName="Scenic Reports"/>
</code>
<text>
<reference value="#DEERS_0"/>
</text>
<statusCode code="completed"/>
<effectiveTime value="547654653325.000"/>
<author>
<time value="4356754356.000"/>
<assignedAuthor>
<id nullFlavor="NA"/>
<addr nullFlavor="NA"/>
<telecom nullFlavor="NA"/>
<assignedPerson>
<name>Location TBD</name>
</assignedPerson>
<representedOrganization>
<id nullFlavor="NA"/>
<name>Location TBD</name>
<telecom nullFlavor="NA"/>
<addr nullFlavor="NA"/>
</representedOrganization>
</assignedAuthor>
</author>
</act>
</entry>
</section>
</component>
XSL
<xsl:template name="section">
<xsl:call-template name="section-title">
<xsl:with-param name="title" select="n1:title"/>
</xsl:call-template>
<xsl:call-template name="section-author"/>
<xsl:call-template name="section-text"/>
<xsl:for-each select="n1:component/n1:section">
<xsl:call-template name="nestedSection">
<xsl:with-param name="margin" select="2"/>
</xsl:call-template>
</xsl:for-each>
</xsl:template>
我想知道我们是否能够在 XSL for-each 循环中编辑 XML 文档中的内容,基于<templateId root="1.1.5.33.4.33"...>
或<code code="87654-1"...>
.
我已经尝试<xsl:if>
和<xsl:choose><xsl:when>
声明无济于事。
解决方案
你也许可以尝试这样的事情:
<xsl:for-each select="templateId">
<xsl:if test="not(@root='1.1.5.33.4.33' and @root='...somethingElse...')">
... your existing code ...
</xsl:if>
</xsl:for-each>
或者干脆
<xsl:for-each select="templateId[not(@root='1.1.5.33.4.33' and @root='...somethingElse...')]">
... your existing code ...
</xsl:for-each>
推荐阅读
- javascript - 正则表达式未验证
- flutter - 使用 wrap 小部件使按钮在空格后对齐
- javascript - 未捕获的类型错误:无法在 javascript 中读取 null 的属性“追加”
- node.js - 写入本地主机 Postgres 返回臭名昭著的“42P01 parse_relation.c”错误
- javascript - 单击元素后工具提示没有隐藏(bootstrap v5.0)
- python - Pip 成功安装模块未找到:ImportError: No module named xlwt
- virtualenv - 对同一个 DAG 中的不同任务使用不同的 pandas 版本(气流)
- android - Android 5.1 选择键盘不起作用
- linux - 在 Arch linux 中更改 powerbutton 角色不起作用?
- r - 按 purrr::cross3 中的位置过滤