在XSL`for-each`循环中编辑出XML文件的一部分 [英] edit out portions of a XML file inside an XSL `for-each` loop

查看:97
本文介绍了在XSL`for-each`循环中编辑出XML文件的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在XSL for-each循环中删除XML文件的某些部分.

I am trying to edit out portions of a XML file inside an XSL for-each loop.

我有一个带有几个模板的XML文件,而XSL文件有一个for-each循环来显示所有模板.

I have an XML file with several templates, and the XSL file has a for-each loop to display all of them.

我的目标是通过针对节点内部的单个templateId来消除某些模板在XSL for-each循环中显示.

My goal was to eliminate certain templates from displaying within the XSL for-each loop by targeting individual templateId's inside the node.

这是代码:

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>

我想知道我们是否能够基于<templateId root="1.1.5.33.4.33"...><code code="87654-1"...>在XSL for-each循环中编辑XML文档中的内容.

I am wondering is we are able to edit out content in an XML document in an XSL for-each loop, based upon <templateId root="1.1.5.33.4.33"...>, or <code code="87654-1"...>.

我尝试了<xsl:if><xsl:choose><xsl:when>语句无济于事.

I have tried <xsl:if> and <xsl:choose><xsl:when> statements to no avail.

推荐答案

您也许可以尝试这样的事情:

You could maybe try something like this :

<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>

这篇关于在XSL`for-each`循环中编辑出XML文件的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆