473,387 Members | 1,611 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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: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:output 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:otherwise>
<xsl:apply-imports/>
</xsl:otherwise>
</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>
Jul 20 '05 #1
2 1714

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(),'QWERTYUIOPASDFGHJKLZXCVBN M','qwertyuiopasdfghjklzxcvbnm')}">
<xsl:apply-templates select="@*|node()"/>
</xsl:element>
</xsl:template>

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

David
Jul 20 '05 #2
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(),'QWERTYUIOPASDFGHJKLZXCVBN M','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

Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Roberto A. F. De Almeida | last post by:
I found that when using negative indices, the slice object passed to __getitem__ depends on the number of slices. An example to clarify: class a: def __getitem__(self, index): return index ...
46
by: Scott Chapman | last post by:
There seems to be an inconsistency here: Python 2.3.2 (#1, Oct 3 2003, 19:04:58) on linux2 >>> 1 == True True >>> 3 == True False >>> if 1: print "true" ....
4
by: John Lehmann | last post by:
I have an interesting problem. I am performing an XSL transform using the System.Xml.Xsl.Transform class. I have a database that contains the XSL style sheet string. And it seems to work pretty...
1
by: shaun | last post by:
Is there some way (standard or non-standard) to access an oracle database during an xslt transform to extract some parameters which will appear in the transform? cheers shaun
1
by: Water Cooler v2 | last post by:
Sorry about the basic question. I have an XML file and I have an XSLT stylesheet that has been constructed to translate the XML file. Now, what next? How do you transform an XML file using the...
7
by: Bilal | last post by:
Hello all, I came across this problem while working out the bugs in my identity trasnformation stylesheets but sidestepped it for later to see if there is an easier/better solution. This is...
2
by: Adam dR. | last post by:
I have an xml file similar to: <menu> <menuitem name="home" show="false"/> <menuitem name="about" show="true"/> <menuitem name="links" show="true"/> <menuitem name="games" show="true"/>...
8
by: Alex Buell | last post by:
I've just written the below as an exercise (don't worry about the lack of checking), but I was wondering why I needed to write a struct with an operator() as a parameter to supply to the STL...
0
by: nimitsis | last post by:
hello I have a problem, which in C is simple to get through of it, but in python seems not so easy to me. I have 2 python threads. Each one do a different work. The first do a computation in a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.