我有一个字符串变量,它有多个节点引用编号,逗号分隔 ex : test_variable = #id1,#id147,#id168
现在我需要获取上述字符串变量的引用号在变量中匹配的所有 xml 节点。
这样我就可以只显示那些符合上述条件的节点的数据。
我很困惑如何溢出和形成条件。请帮忙
<xsl:variable name="test_variable" select="substring-after($vMinMaxVar,'|')"/>
<xsl:message><xsl:text>PrintingTesting_Variable:-</xsl:text><xsl:value-of select="$test_variable"/></xsl:message>
所以如果我打印上面的行.我会有一个价值,即 PrintingTesting_Variable:-#id1,#id147,#id168(此输出可以是单值或带逗号的多值(。
现在我需要回到 xml 并仅过滤 xml 节点,该节点的标签中只有这些参考编号
供参考的 XML 内容示例:-
<?xml version="1.0" encoding="utf-8"?>
<Sample xmlns="http://www.sample.org/Schemas/xyzwSchema"
language="en-us" time="11:16:55" schemaVersion="6" author="John" date="2019-07-26">
<Process id="id234" instancedRef="#id1" >
<UserData id="id41">
<UserValue title="Mfg0allocated_time" type="real" value="23.4"></UserValue>
</Process>
<Process id="id235" instancedRef="#id23" >
<UserData id="id42">
<UserValue title="Mfg0allocated_time" type="real" value="23.4"></UserValue>
</Process>
<Process id="id236" instancedRef="#id147" >
<UserData id="id43">
<UserValue title="Mfg0allocated_time" type="real" value="23.4"></UserValue>
</Process>
<Process id="id237" instancedRef="#id168" >
<UserData id="id44">
<UserValue title="Mfg0allocated_time" type="real" value="23.4"></UserValue>
</Process>
<Process id="id238" instancedRef="#id196" >
<UserData id="id45">
<UserValue title="Mfg0allocated_time" type="real" value="23.4"></UserValue>
</Process>
<Process id="id239" instancedRef="#id241" >
<UserData id="id46">
<UserValue title="Mfg0allocated_time" type="real" value="23.4"></UserValue>
</Process>
</Sample>
我期望一个变量包含所有这些过滤器节点的输出。
考虑以下示例:
XML(格式正确!!(
<Sample xmlns="http://www.sample.org/Schemas/xyzwSchema" language="en-us" time="11:16:55" schemaVersion="6" author="John" date="2019-07-26">
<Process id="id234" instancedRef="#id1">
<UserData id="id41"/>
<UserValue title="Mfg0allocated_time" type="real" value="23.4"/>
</Process>
<Process id="id235" instancedRef="#id23">
<UserData id="id42"/>
<UserValue title="Mfg0allocated_time" type="real" value="23.4"/>
</Process>
<Process id="id236" instancedRef="#id147">
<UserData id="id43"/>
<UserValue title="Mfg0allocated_time" type="real" value="23.4"/>
</Process>
<Process id="id237" instancedRef="#id168">
<UserData id="id44"/>
<UserValue title="Mfg0allocated_time" type="real" value="23.4"/>
</Process>
<Process id="id238" instancedRef="#id196">
<UserData id="id45"/>
<UserValue title="Mfg0allocated_time" type="real" value="23.4"/>
</Process>
<Process id="id239" instancedRef="#id241">
<UserData id="id46"/>
<UserValue title="Mfg0allocated_time" type="real" value="23.4"/>
</Process>
</Sample>
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns="http://www.sample.org/Schemas/xyzwSchema"
exclude-result-prefixes="ns">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:param name="references">#id1,#id147,#id168</xsl:param>
<xsl:template match="/ns:Sample">
<xsl:copy>
<xsl:copy-of select="ns:Process[contains(concat($references, ','), concat(@instancedRef, ','))]"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
结果
<?xml version="1.0" encoding="UTF-8"?>
<Sample xmlns="http://www.sample.org/Schemas/xyzwSchema">
<Process id="id234" instancedRef="#id1">
<UserData id="id41"/>
<UserValue title="Mfg0allocated_time" type="real" value="23.4"/>
</Process>
<Process id="id236" instancedRef="#id147">
<UserData id="id43"/>
<UserValue title="Mfg0allocated_time" type="real" value="23.4"/>
</Process>
<Process id="id237" instancedRef="#id168">
<UserData id="id44"/>
<UserValue title="Mfg0allocated_time" type="real" value="23.4"/>
</Process>
</Sample>