XML transform inconsistency with different processors

P

Peter Clifton

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:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ren="http://www.ora.com/namespaces/rename">

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

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

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


and these are the referenced stylesheets during the process


--- TableDrivenRename.xsl

<xsl:stylesheet 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(current())]">
<xsl:element name="{$lookup/ren:element[@from=name(current())]/
@to}">
<xsl:apply-templates select="@*"/>
<xsl:apply-templates/>
</xsl:element>
</xsl:when>
<xsl:eek:therwise>
<xsl:apply-imports/>
</xsl:eek:therwise>
</xsl:choose>
</xsl:template>


--- copy.xsl

<xsl:stylesheet 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>
 
D

David Carlisle

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|TITLE">
<xsl:element name="{translate(name(),'QWERTYUIOPASDFGHJKLZXCVBNM','qwertyuiopasdfghjklzxcvbnm')}">
<xsl:apply-templates select="@*|node()"/>
</xsl:element>
</xsl:template>

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

David
 
P

Peter Clifton

David Carlisle said...
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|TITLE">
<xsl:element name="{translate(name(),'QWERTYUIOPASDFGHJKLZXCVBNM','qwertyuiopasdfghjklzxcvbnm')}">
<xsl:apply-templates select="@*|node()"/>
</xsl:element>
</xsl:template>

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

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top