Question

Here are my files:

example.xml

 <?xml version="1.0" encoding="UTF-8"?>
    <bsp>
<numbers>
       <string>one</string>
       <string>two</string>
       <string>three</string>
       <string>one</string>
       <string>two</string>
       <string>four</string>
       <string>fife</string>
    </numbers>
</bsp>

complete.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <bsp>
<first>
    <team>
       <member>one</member>
       <member>three</member>
    </team>
    </first>
    <second>
    <mems>
       <member>four</member>
       <member>five</member>    
    </mems>
    </second>
</bsp>

Output

All which are not in complete (exact match of the value of member and *stringÜ ). How to do that in xslt 2.0 with a huge file?

First we need access to the documents.

expected output

      <string>two</pupil>
      <string>two</pupil>
      <string>fife</string>

What are the ways to accomplish this, which is recommended? edit Example now more abstract...

Was it helpful?

Solution

If you are processing pupils.xml the following should work

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">

    <xsl:output method="xml"/>

    <xsl:template match="/">
        <xsl:for-each select="school">
            <!-- to insert header for the school -->
            <xsl:for-each select="class">
                <!-- to insert header for the class -->
                <xsl:for-each select="pupil">
                    <xsl:if test="not(document('sports.xml')//member = .)">
                        <xsl:copy-of select="."/>
                    </xsl:if>
                </xsl:for-each>
            </xsl:for-each>
        </xsl:for-each>
    </xsl:template>

</xsl:stylesheet>

Where:

  • not( - get only those who don't match
  • document('sports.xml') from this file
  • //member who are enclosed in <member> at any depth
  • = .) who match the student we are processing.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top