Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are two immediate solutions:</p> <p><strong>Solution 1</strong>.</p> <p>You can first apply a simple transform to the two documents that will delete the elements that should not be compared. Then, compare the results ing two documents -- exactly with your current code. Here is the transformation:</p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt; &lt;xsl:output omit-xml-declaration="yes" indent="yes"/&gt; &lt;xsl:strip-space elements="*"/&gt; &lt;xsl:template match="node()|@*"&gt; &lt;xsl:copy&gt; &lt;xsl:apply-templates select="node()|@*"/&gt; &lt;/xsl:copy&gt; &lt;/xsl:template&gt; &lt;xsl:template match="Name|Team|Pos"/&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p><strong>When this transformation is applied to the provided XML document</strong>:</p> <pre><code>&lt;Stats Date="2011-01-01"&gt; &lt;Player Rank="1"&gt; &lt;Name&gt;Sidney Crosby&lt;/Name&gt; &lt;Team&gt;PIT&lt;/Team&gt; &lt;Pos&gt;C&lt;/Pos&gt; &lt;GP&gt;39&lt;/GP&gt; &lt;G&gt;32&lt;/G&gt; &lt;A&gt;33&lt;/A&gt; &lt;PlusMinus&gt;20&lt;/PlusMinus&gt; &lt;PIM&gt;29&lt;/PIM&gt; &lt;PP&gt;10&lt;/PP&gt; &lt;SH&gt;1&lt;/SH&gt; &lt;GW&gt;3&lt;/GW&gt; &lt;Shots&gt;0&lt;/Shots&gt; &lt;ShotPctg&gt;154&lt;/ShotPctg&gt; &lt;TOIPerGame&gt;20.8&lt;/TOIPerGame&gt; &lt;ShiftsPerGame&gt;21:54&lt;/ShiftsPerGame&gt; &lt;FOWinPctg&gt;22.6&lt;/FOWinPctg&gt; &lt;/Player&gt; &lt;/Stats&gt; </code></pre> <p><strong>the wanted resulting document is produced</strong>:</p> <pre><code>&lt;Stats Date="2011-01-01"&gt; &lt;Player Rank="1"&gt; &lt;GP&gt;39&lt;/GP&gt; &lt;G&gt;32&lt;/G&gt; &lt;A&gt;33&lt;/A&gt; &lt;PlusMinus&gt;20&lt;/PlusMinus&gt; &lt;PIM&gt;29&lt;/PIM&gt; &lt;PP&gt;10&lt;/PP&gt; &lt;SH&gt;1&lt;/SH&gt; &lt;GW&gt;3&lt;/GW&gt; &lt;Shots&gt;0&lt;/Shots&gt; &lt;ShotPctg&gt;154&lt;/ShotPctg&gt; &lt;TOIPerGame&gt;20.8&lt;/TOIPerGame&gt; &lt;ShiftsPerGame&gt;21:54&lt;/ShiftsPerGame&gt; &lt;FOWinPctg&gt;22.6&lt;/FOWinPctg&gt; &lt;/Player&gt; &lt;/Stats&gt; </code></pre> <p><strong>Solution 2.</strong></p> <p><strong>This is a complete XSLT 1.0 solution</strong> (for convenience only, the second XML document is embedded in the transformation code):</p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt; &lt;xsl:output omit-xml-declaration="yes" indent="yes"/&gt; &lt;xsl:strip-space elements="*"/&gt; &lt;xsl:variable name="vrtfDoc2"&gt; &lt;Stats Date="2011-01-01"&gt; &lt;Player Rank="2"&gt; &lt;Name&gt;John Smith&lt;/Name&gt; &lt;Team&gt;NY&lt;/Team&gt; &lt;Pos&gt;D&lt;/Pos&gt; &lt;GP&gt;38&lt;/GP&gt; &lt;G&gt;32&lt;/G&gt; &lt;A&gt;33&lt;/A&gt; &lt;PlusMinus&gt;15&lt;/PlusMinus&gt; &lt;PIM&gt;29&lt;/PIM&gt; &lt;PP&gt;10&lt;/PP&gt; &lt;SH&gt;1&lt;/SH&gt; &lt;GW&gt;4&lt;/GW&gt; &lt;Shots&gt;0&lt;/Shots&gt; &lt;ShotPctg&gt;158&lt;/ShotPctg&gt; &lt;TOIPerGame&gt;20.8&lt;/TOIPerGame&gt; &lt;ShiftsPerGame&gt;21:54&lt;/ShiftsPerGame&gt; &lt;FOWinPctg&gt;22.6&lt;/FOWinPctg&gt; &lt;/Player&gt; &lt;/Stats&gt; &lt;/xsl:variable&gt; &lt;xsl:variable name="vDoc2" select= "document('')/*/xsl:variable[@name='vrtfDoc2']/*"/&gt; &lt;xsl:template match="node()|@*" name="identity"&gt; &lt;xsl:param name="pDoc2"/&gt; &lt;xsl:copy&gt; &lt;xsl:apply-templates select="node()|@*"&gt; &lt;xsl:with-param name="pDoc2" select="$pDoc2"/&gt; &lt;/xsl:apply-templates&gt; &lt;/xsl:copy&gt; &lt;/xsl:template&gt; &lt;xsl:template match="/"&gt; &lt;xsl:apply-templates select="*"&gt; &lt;xsl:with-param name="pDoc2" select="$vDoc2"/&gt; &lt;/xsl:apply-templates&gt; ----------------------- &lt;xsl:apply-templates select="$vDoc2"&gt; &lt;xsl:with-param name="pDoc2" select="/*"/&gt; &lt;/xsl:apply-templates&gt; &lt;/xsl:template&gt; &lt;xsl:template match="Player/*"&gt; &lt;xsl:param name="pDoc2"/&gt; &lt;xsl:if test= "not(. = $pDoc2/*/*[name()=name(current())])"&gt; &lt;xsl:call-template name="identity"/&gt; &lt;/xsl:if&gt; &lt;/xsl:template&gt; &lt;xsl:template match="Name|Team|Pos" priority="20"/&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p><strong>when this transformation is applied on the same first document as above, the correct diffgrams are produced</strong>:</p> <pre><code>&lt;Stats Date="2011-01-01"&gt; &lt;Player Rank="1"&gt; &lt;GP&gt;39&lt;/GP&gt; &lt;PlusMinus&gt;20&lt;/PlusMinus&gt; &lt;GW&gt;3&lt;/GW&gt; &lt;ShotPctg&gt;154&lt;/ShotPctg&gt; &lt;/Player&gt; &lt;/Stats&gt; ----------------------- &lt;Stats xmlns:xsl="http://www.w3.org/1999/XSL/Transform" Date="2011-01-01"&gt; &lt;Player Rank="2"&gt; &lt;GP&gt;38&lt;/GP&gt; &lt;PlusMinus&gt;15&lt;/PlusMinus&gt; &lt;GW&gt;4&lt;/GW&gt; &lt;ShotPctg&gt;158&lt;/ShotPctg&gt; &lt;/Player&gt; &lt;/Stats&gt; </code></pre> <p><strong>How this works</strong>:</p> <ol> <li><p><strong>The transformation is applied on the first document</strong>, passing the second document as parameter.</p></li> <li><p><strong>This produces an XML document whose only leaf element nodes are the ones that have different value</strong> than the corresponding leaf element nodes in the second document.</p></li> <li><p><strong>The same processing is performed as in 1. above, but this time on the second document</strong>, passing the first document as parameter.</p></li> <li><p><strong>This produces a second diffgram</strong>: an XML document whose only leaf element nodes are the ones that have different value** than the corresponding leaf element nodes in the first document</p></li> </ol>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload