0

Is there any way that I can use XSLT to process again(2nd time) the XML that is obtained during the first processing?

To be more clear,

I got the following output, while the transformation is going on,

<processPrototypes>
     <orderPrecedenceSpec origin="xxx"
                          target="yyy"
                          orderType="directOrder"/>
     <orderPrecedenceSpec origin="abc"
                          target="lmn"
                          orderType="directOrder"/>
     <orderPrecedenceSpec origin="xxx"
                          target="yyy"
                          orderType="directOrder"/>
     <orderPrecedenceSpec origin="abc"
                          target="lmn"
                          orderType="directOrder"/>
  </processPrototypes>

In my xslt, the line/template that does this part is,

   <processPrototypes>

        <xsl:call-template name="help">
        </xsl:call-template>

    </processPrototypes>

    What to do in the next line here ? to modify the output created by the above template ?

Now my question is can I be able to process the "processPrototypes" output to remove the duplication there ? in the same xslt file just in the next line after calling the template ?

So that after processing it again, my final output should look like (without duplication),

     <processPrototypes>
         <orderPrecedenceSpec origin="xxx"
                              target="yyy"
                              orderType="directOrder"/>
         <orderPrecedenceSpec origin="abc"
                              target="lmn"
                              orderType="directOrder"/>
      </processPrototypes>
Legolas
  • 805
  • 1
  • 11
  • 24
  • Possible duplicate of [XSLT 1.0 - Create node set and pass as a parameter](https://stackoverflow.com/questions/3880499/xslt-1-0-create-node-set-and-pass-as-a-parameter) – JLRishe Apr 12 '19 at 15:02

1 Answers1

1

If your XSLT processor supports some variant of the node-set() function, you can do something like this:

<xsl:variable name="prototypes">
  <processPrototypes>
    <xsl:call-template name="help" />
  </processPrototypes>
</xsl:variable>

<xsl:apply-templates select="exslt:node-set($prototypes)" />

When you create a variable that contains markup or XSLT processing like apply-templates, etc., like the prototypes variable above, this creates a node fragment, which cannot be accessed the way you would access a node-set. The node-set() function converts that node fragment into a node-set so that you can perform XSLT processing on it, traverse it with XPath, and so on. I believe this function is available in a handful of major XSLT processors.

JLRishe
  • 99,490
  • 19
  • 131
  • 169
  • @Legolas Isn't Saxon an XSLT 3.0 processor? Your question is tagged with XSLT 1.0. – JLRishe Apr 12 '19 at 16:21
  • I am using saxon 9,8HE online editor just to see quick outputs...But actually I will be using only xslt 1.0 (xalan) – Legolas Apr 12 '19 at 16:33
  • @Legolas The `node-set` function does not exist in Saxon because Saxon is an XSLT 3.0 (or 2.0) processor and `node-set` would be irrelevant there. What environment are you executing your xalan in? According to the page I linked to, the namespace to use would differ depending on whether you're using xalan-J or xalan-C. – JLRishe Apr 13 '19 at 18:39
  • I am using xalan-J 2.7.1... but it works with saxon as well... https://xsltfiddle.liberty-development.net/bFN1y9s/8 – Legolas Apr 14 '19 at 12:52