如何使用 XSL 获取基于字符串值的 xml 节点?

How to get the xml node based on a String values using XSL?

我有一个字符串变量,它有多个节点引用号,用逗号分隔 ex : test_variable = #id1,#id147,#id168

现在我需要获取所有 xml 个节点,其中上述字符串变量的引用号在一个变量中匹配。

这样我就可以只显示符合上述条件的那些节点的数据。

我很困惑如何溢出并形成 condition.Please 帮助

<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>

我希望得到一个输出,其中一个变量包含所有那些 filtererd 节点。

考虑以下示例:

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>