2

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

  • Is the student identified by name in the data? If so the solution will be limited by potential namespace collisions. Two students both named "Bob Smith" for instance. – Jason Aller Apr 14 '14 at 21:45
  • hmmm, it could be that we have Bob Smith in both files several times. I just wanna know, if one of the instances of "examples" is not part of "complete.xml". I rewrote the code more abstractly now. – user3500768 Apr 14 '14 at 22:16

1 Answers1

1

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.
Jason Aller
  • 3,541
  • 28
  • 38
  • 38