我试图根据决策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>
Run Code Online (Sandbox Code Playgroud)
决策文件:
<TopLevel>
<DATA1>
<Available>Y</Available>
</DATA1>
<DATA2>
<Available>N</Available>
</DATA2>
</TopLevel>
Run Code Online (Sandbox Code Playgroud)
处理时的XSLT必须输出结果文件(基于决策文件中的YES或NO).
<Level1>
<Level2>
<Attribute1>1</Attribute1>
<Attribute2>2</Attribute2>
</Level2>
</Level1>
Run Code Online (Sandbox Code Playgroud)
我必须承认我之前从未做过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>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9171 次 |
| 最近记录: |