又是我,但这次我遇到了一个真正的问题......我有一个 XML,我必须使用另一个 XML 的过滤器将它转换为另一个 XML
文件_in.xml:
<?xml version="1.0" encoding="ISO-8859-15"?>
<root>
<item>
<server>001023541</server>
<name>P1</name>
<desc>Production</desc>
<status>1</status>
<ram>1024</ram>
<hdd>8 To</hdd>
</item>
<item>
<server>201012345</server>
<name>P2</name>
<desc>Production</desc>
<status>4</status>
<ram>2048</ram>
<hdd>8 To</hdd>
</item>
<item>
<server>120332416</server>
<name>P1</name>
<desc>Production</desc>
<status>2</status>
<ram>8196</ram>
<hdd>8 To</hdd>
</item>
</root>
还有另一个 XML:
过滤器.xml
<?xml version="1.0" encoding="ISO-8859-15"?>
<Filtre>
<Bloc5>
<Part1>
<EAN>001023541</EAN>
<EAN>012356549</EAN>
<EAN>012356559</EAN>
<EAN>012356569</EAN>
</Part1>
<Part2>
<EAN>201012345</EAN>
<EAN>201012346</EAN>
<EAN>201012347</EAN>
</Part2>
</Bloc5>
</Filtre>
如果 /root/item/server 与 /Filtre/Bloc5/Part1/EAN 的元素匹配,我替换
<item>
<server>001023541</server>
<name>P1</name>
<desc>Production</desc>
<status>1</status>
<ram>1024</ram>
<hdd>8 To</hdd>
</item>
经过
<item>
<server>MAIN</server>
<status>PRODUCTION</status>
</item>
否则,如果 /root/item/server 与 /Filtre/Bloc5/Part2/EAN 的元素匹配,我替换
<item>
<server>201012345</server>
<name>P2</name>
<desc>Production</desc>
<status>4</status>
<ram>2048</ram>
<hdd>8 To</hdd>
</item>
经过
<item>
<server>BACKUP</server>
<status>STOPPED</status>
</item>
另一个自动替换,如:
<item>
<server>120332416</server>
<name>P1</name>
<desc>Production</desc>
<status>2</status>
<ram>8196</ram>
<hdd>8 To</hdd>
</item>
经过
<item>
<name>OFFLINE</name>
<desc>Production</desc>
</item>
我通过这种方式获得了 XML(用于过滤)的名称:
<!-- filter settings -->
<xsl:param name="filter_xml" />
<xsl:variable name="filter" select="document('$filter_xml')" />
还有我的代码:
<xsl:for-each select="root/item">
<xsl:choose>
<xsl:when test="index-of(($filter/Filtre/Bloc5/Part1/EAN), ./server)">
<item>
<server>MAIN</server>
<status>PRODUCTION</status>
</item>
</xsl:when>
<xsl:when test="index-of(($filter/Filtre/Bloc5/Part2/EAN), ./server)" >
<item>
<server>BACKUP</server>
<status>STOPPED</status>
</item>
</xsl:when >
<xsl:otherwise>
<item>
<name>OFFLINE</name>
<desc>Production</desc>
</item>
</xsl:otherwise>
</xsl:for-each>
但这不起作用...