XML transform inconsistency with different processors

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Peter Clifton

    XML transform inconsistency with different processors

    Hello all,

    I am very new to this subject and learning by example.

    I have a small inconsistency in an XML file when transformed using
    different processors. I was wondering if someone could shed light on why
    this is and if possible how to resolve the inconsistency.

    I am attempting to change the element names in the source XML file from
    upper to lowercase. I have used (slightly modified) examples from the
    XSLT Cookbook, O'Reilly Press.

    If I use Xalan (Java 2.5.1 I think) then the transformed XML file has
    the following route element and undesired attribute:

    <play xmlns:ren="http ://www.ora.com/namespaces/rename">

    If I use Saxon 6.5.3 or MSXML4.0, I end up with the desired root element
    of:

    <play>

    The <TITLE> element is always transformed to <title>

    I am using oXygen 6.0 as my development environment.

    Thanks in advance for any assistance offered.

    Peter Clifton


    This is the example XML file I am transforming.

    ---Source.xml

    <?xml version="1.0"?>
    <PLAY>
    <TITLE>Play Title</TITLE>
    </PLAY>


    This is the stylesheet I am using


    --- LowerCase.xsl

    <xsl:styleshe et version="1.0"
    xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
    xmlns:ren="http ://www.ora.com/namespaces/rename">

    <xsl:import href="TableDriv enRename.xsl"/>

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

    <xsl:variable name="lookup" select="documen t('')/*[ren:*]"/>
    <ren:element from="PLAY" to="play"/>
    <ren:element from="TITLE" to="title"/>
    </xsl:stylesheet>


    and these are the referenced stylesheets during the process


    --- TableDrivenRena me.xsl

    <xsl:styleshe et version="1.0"
    xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
    xmlns:ren="http ://www.ora.com/namespaces/rename">

    <xsl:import href="copy.xsl"/>

    <!--Override in importing stylesheet -->
    <xsl:variable name="lookup" select="/.."/>

    <xsl:template match="*">
    <xsl:choose>
    <xsl:when test="$lookup/ren:element[@from=name(curr ent())]">
    <xsl:element name="{$lookup/ren:element[@from=name(curr ent())]/
    @to}">
    <xsl:apply-templates select="@*"/>
    <xsl:apply-templates/>
    </xsl:element>
    </xsl:when>
    <xsl:otherwis e>
    <xsl:apply-imports/>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:template>


    --- copy.xsl

    <xsl:styleshe et version="1.0"
    xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">

    <xsl:template match="/ | node() | @* | comment() | processing-
    instruction()">
    <xsl:copy>
    <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
    </xsl:template>

    </xsl:stylesheet>
  • David Carlisle

    #2
    Re: XML transform inconsistency with different processors


    That looks like a bug in xalan: xsl:element should not copy the in scope
    ren namespace.

    It's a very inefficient way of coding the name change though, having to
    parse the stylesheet twice (once as a styleseet and once as an input
    document) and then having to look up the element names in your table all
    the time. A much more direct way to code things would be to have
    copy.xsl as you have it and then templates of the form

    <xsl:template match="PLAY|TIT LE">
    <xsl:element name="{translat e(name(),'QWERT YUIOPASDFGHJKLZ XCVBNM','qwerty uiopasdfghjklzx cvbnm')}">
    <xsl:apply-templates select="@*|node ()"/>
    </xsl:element>
    </xsl:template>

    Or if you want all elements lowercased, replace PLAY|TITLE by *

    David

    Comment

    • Peter Clifton

      #3
      Re: XML transform inconsistency with different processors

      David Carlisle said...[color=blue]
      >
      > That looks like a bug in xalan: xsl:element should not copy the in scope
      > ren namespace.
      >
      > It's a very inefficient way of coding the name change though, having to
      > parse the stylesheet twice (once as a styleseet and once as an input
      > document) and then having to look up the element names in your table all
      > the time. A much more direct way to code things would be to have
      > copy.xsl as you have it and then templates of the form
      >
      > <xsl:template match="PLAY|TIT LE">
      > <xsl:element name="{translat e(name(),'QWERT YUIOPASDFGHJKLZ XCVBNM','qwerty uiopasdfghjklzx cvbnm')}">
      > <xsl:apply-templates select="@*|node ()"/>
      > </xsl:element>
      > </xsl:template>
      >
      > Or if you want all elements lowercased, replace PLAY|TITLE by *
      >[/color]

      Thank you so much for responding and supplying a more efficient approach
      to solving the problem.

      I am taking my first steps into developing an environment for producing
      technical documents XML > XSL-FO > PDF

      It has taken me a while just to get all the acronyms and XML
      technologies straight in my head ;-)

      I have begun to realise that the critical glue in all of this is going
      to be XSL and associated technologies so this is where I have decided to
      start learning.

      Thanks once again.

      Peter





      Comment

      Working...