0

I have a string variable which has multiple node refs numbers with comma separated ex : test_variable = #id1,#id147,#id168

Now I need to get all the xml nodes where reference numbers of the above string variable matches in a variable.

So that i cam Show up data of only those nodes which have matched the above criteria.

I am confused how to spilt and form the condition.Please help

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

so if i print the above line . I would be having an value i.e. PrintingTesting_Variable:-#id1,#id147,#id168 (This ouput can be single value or Multivalued with Commaseprated).

Now i need to go back to xml and filter the xml nodes only which is having only these Reference numbers inside its tag

Sample Xml Content for Reference :-

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

I expect a output where a Variable holds all the those filtererd nodes.

3
  • Are you really restricted to XSLT 1? If so, which XSLT 1 processor exactly do you use? Does it support an extension function to tokenize your a string, like exslt.org/str/functions/tokenize/index.html? Commented Aug 31, 2019 at 8:40
  • Your XML is missing closing tags for UserData. Commented Aug 31, 2019 at 9:46
  • "I expect a output where a Variable holds all the those filtererd nodes." There is no such thing. Variables cease to exist when processing ends. The output must be a document (XML, HTML or text). Commented Aug 31, 2019 at 10:09

1 Answer 1

1

Consider the following example:

XML (well-formed!!!)

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

Result

<?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>
Sign up to request clarification or add additional context in comments.

1 Comment

Hi Micheal,Really thanks your suggestion It really worked for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.