XSLT Get two different output for the same XML input for the same XSL

I am trying to use my XSLT code in an online tool [XSLT 1.0 processor]:

http://www.freeformatter.com/xsl-transformer.html

Recently, I had to use xs:dateTimeand therefore started using a tool that uses the XSLT 2.0 processor, http://xsltransform.net/

Now, when I tried to solve the problem, I see that I get different output for the same XML input in these two processors. The code shown here is not the real code I'm working on; this should mimic the strange exit that I came across.

XML:

<?xml version="1.0" encoding="UTF-8"?>
<items>
    <book> 
        <title></title>
    </book>
    <phone>apple</phone>
</items>

XSLT:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:output method="xml" version="1.0" encoding="UTF-8"
        indent="yes" />

    <xsl:template match="/">
        <items><xsl:apply-templates select="items/*" /></items>
    </xsl:template>

    <!-- ignore empty elements -->
    <xsl:template match="*[not(normalize-space())]" />


    <xsl:template match="book">
      <newbook><xsl:apply-templates /></newbook>
    </xsl:template>

    <xsl:template match="title">
      <newtitle><xsl:apply-templates /></newtitle>
    </xsl:template>

    <xsl:template match="phone">
      <newphone><xsl:apply-templates /></newphone>
    </xsl:template>

</xsl:stylesheet>

Conclusion from http://xsltransform.net/: [Conclusion 1]

<?xml version="1.0" encoding="UTF-8"?>
<items>
   <newbook> 
        <newtitle/>
    </newbook>
   <newphone>apple</newphone>
</items>

Exit from http://www.freeformatter.com/xsl-transformer.html: [pin 2]

<?xml version="1.0" encoding="UTF-8"?>
<items>
   <newphone>apple</newphone>
</items>

XML output 2.

, ?

note: SO: XSL?, .

Edit

, , :

http://xsltransform.net/ output 1

http://www.freeformatter.com/xsl-transformer.html output 2

[02/10/2014] -

, . , , .

<xsl:template match="*[not(normalize-space())]" />

XSLT1, XSLT2. , 2

* 1 - http://xsltransform.net/: *

  • @michael.hor257k, , <book>.
  • Saxon-HE 9.5.1.3, 1, , , ​​ [@Michael Kay ]
  • @Ian Roberts, , . : <xsl:template match="*[not(normalize-space())]" priority="2"/> , Saxon, .
+3
4

2 . Oxygen/XML, XSLT1, XSLT2 .

<xsl:template match="*[not(normalize-space())]" />

XSLT1, XSLT2.

, -, 1, .

+3

Saxon-EE 9.5.1.4; xsltransform Saxon-HE 9.5.1.3. , , ; , , .

+3

, <book> :

<xsl:template match="*[not(normalize-space())]" />

:

<xsl:template match="book">
  <newbook><xsl:apply-templates /></newbook>
</xsl:template>

<title>. XSLT, , XSLT.

http://xsltransform.net/ Saxon 9.5.1 - XSLT 2.0. ( ), XSLT 1.0 (Saxon 6.5 Xalan 2.7.1).

, XSLT 2.0 XSLT 1.0; Saxon 8.9 - XSLT 2.0. , ( , ).

+2

2 , 1.0 2.0 XSLT , . , .

, , . XSLT, , , , .

However, a match associated with a hierarchy (for example match="items/book") or something more complex than just the name of one element will have the same priority *[....]as the default rule - 0.5. If you have any of these types of templates in your real XSLT, you need to add an explicit priority above 0.5 to the empty-suppressor template.

<xsl:template match="*[not(normalize-space())]" priority="2"/>
+1
source

All Articles