XSLT将2个XML文件作为输入并生成输出XML文件
发布时间:2020-12-16 23:02:49 所属栏目:百科 来源:网络整理
导读:我试图根据决策xml文件(Input2)中可用的数据从主xml文件(Input1)生成输出 XML文件. 主文件 Level1 Level2 LinkedToDATA1/LinkedTo !DATA1 in the decision file Attribute11/Attribute1 Attribute22/Attribute2 /Level2 Level2 LinkedToDATA2/LinkedTo Attri
我试图根据决策xml文件(Input2)中可用的数据从主xml文件(Input1)生成输出
XML文件.
主文件 <Level1> <Level2> <LinkedTo>DATA1</LinkedTo> <!DATA1 in the decision file> <Attribute1>1</Attribute1> <Attribute2>2</Attribute2> </Level2> <Level2> <LinkedTo>DATA2</LinkedTo> <Attribute1>3</Attribute1> <Attribute2>4</Attribute2> </Level2> </Level1> 决策文件: <TopLevel> <DATA1> <Available>Y</Available> </DATA1> <DATA2> <Available>N</Available> </DATA2> </TopLevel> 处理时的XSLT必须输出结果文件(基于决策文件中的YES或NO). <Level1> <Level2> <Attribute1>1</Attribute1> <Attribute2>2</Attribute2> </Level2> </Level1> 我必须承认我之前从未做过XML的事情,但这是可行性研究所必需的.什么应该在XSLT?我可以使用你的答案并扩展这个概念. 或者如果有替代方案(python,C#,C,C等),也欢迎这些.我可以使用C/C++或任何面向过程的语言进行管理. 解决方法
使用
document 功能.将URI传递给决策XML,例如:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" indent="yes"/> <xsl:template match="Level1"> <xsl:copy> <xsl:apply-templates select="Level2"/> </xsl:copy> </xsl:template> <xsl:template match="Level2"> <xsl:if test="document('Decision.xml')/TopLevel/*[ name() = current()/LinkedTo and Available = 'Y']"> <xsl:copy> <xsl:apply-templates select="*[not(self::LinkedTo)]"/> </xsl:copy> </xsl:if> </xsl:template> <xsl:template match="*"> <xsl:copy-of select="."/> </xsl:template> </xsl:stylesheet> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |