edit out portions of a XML file inside an XSL `for-each` loop

大兔子大兔子 提交于 2020-06-17 09:38:28

问题


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

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

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

This is the code:

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>

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

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


回答1:


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>

or simply

<xsl:for-each select="templateId[not(@root='1.1.5.33.4.33' and @root='...somethingElse...')]">
  ... your existing code ...
</xsl:for-each>


来源:https://stackoverflow.com/questions/62323803/edit-out-portions-of-a-xml-file-inside-an-xsl-for-each-loop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!