Xslt XSL如何在输出中排除一些子项?
初学者XSL问题..我知道有类似的问题和答案张贴,但我不知道如何将它们应用到我的XSLT 我的源XML看起来像(这只是一个更大的XML文件的片段)Xslt XSL如何在输出中排除一些子项?,xslt,Xslt,初学者XSL问题..我知道有类似的问题和答案张贴,但我不知道如何将它们应用到我的XSLT 我的源XML看起来像(这只是一个更大的XML文件的片段) 4. 4. 或:wt.part.WTPart:121581:416986630-1502721046884-982634822-1-0-0-127@ODIGettingStarted.tri.co.uk 组织管理员 2017-09-27 08:34:31美国东部时间 恩努斯 CRP1 我想从输出中排除区域设置和目标节点。 我的完整解决方案将更加复
4.
4.
或:wt.part.WTPart:121581:416986630-1502721046884-982634822-1-0-0-127@ODIGettingStarted.tri.co.uk
组织管理员
2017-09-27 08:34:31美国东部时间
恩努斯
CRP1
我想从输出中排除区域设置和目标节点。
我的完整解决方案将更加复杂,需要我将XML分为三部分,因此我使用了以下代码,但到目前为止我使用的相关代码是:-
<?xml version = "1.0" encoding = "UTF-8"?>
<xsl:stylesheet version = "2.0"
xmlns:xsl = "http://www.w3.org/1999/XSL/Transform">
<xsl:param name ="outputFileDir" select="'file:///D:/workspace/TPHMOT_xsl/TPHMOT_xsl/xsl_output'"/>
<xsl:template match ="/">
<xsl:result-document href="{$outputFileDir}/ESI_ItemMasters_1.xml" method="xml" indent="yes">
<COLLECTION>
<xsl:apply-templates select="COLLECTION/Release"/>
</COLLECTION>
</xsl:result-document>
<xsl:result-document href="{$outputFileDir}/ESI_ConfigurableItem_1.xml" method="xml" indent="yes">
<COLLECTION>
<xsl:apply-templates select="COLLECTION/Release"/>
</COLLECTION>
</xsl:result-document>
<xsl:result-document href="{$outputFileDir}/ESI_GenericBOM_1.xml" method="xml" indent="yes">
<COLLECTION>
<xsl:apply-templates select="COLLECTION/Release"/>
</COLLECTION>
</xsl:result-document>
</xsl:template>
<xsl:template match="Release">
<xsl:copy-of select="self::node()"/>
</xsl:template>
</xsl:stylesheet>
这个输出
<?xml version="1.0" encoding="UTF-8"?>
<COLLECTION>
<Release NAME="Release" TYPE="Unknown" STATUS="0">
<Transaction>
<TransactionNumber>4</TransactionNumber>
<ReleaseNumber>4</ReleaseNumber>
<PrimaryObjectID>OR:wt.part.WTPart:121581:416986630-1502721046884-982634822-1-0-0-127@ODIGettingStarted.tri.co.uk</PrimaryObjectID>
<CreatedBy>orgadmin</CreatedBy>
<CreatedDate>2017-09-27 08:34:31 EDT</CreatedDate>
<Locale>en_US</Locale>
<Destination>CRP1</Destination>
</Transaction>
</Release>
</COLLECTION>
4.
4.
或:wt.part.WTPart:121581:416986630-1502721046884-982634822-1-0-0-127@ODIGettingStarted.tri.co.uk
组织管理员
2017-09-27 08:34:31美国东部时间
恩努斯
CRP1
如何调整XSL以排除区域设置和目标子节点
非常感谢您提供的任何帮助 而不是在中复制完整的元素
<xsl:template match="Release">
<xsl:copy-of select="self::node()"/>
</xsl:template>
您只需要使用标识转换
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
然后清空模板,以防止复制不需要的元素:
<xsl:template match="Locale | Destination"/>
谢谢,这确实奏效了,我需要了解这个应用模板模式,它还没有完全融入其中!
<xsl:template match="Locale | Destination"/>