Aravind
Aravind

Reputation: 845

how to transform again the XML output obtained from XSLT

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>

Upvotes: 0

Views: 168

Answers (1)

JLRishe
JLRishe

Reputation: 101738

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.

Upvotes: 1

Related Questions