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"/>
<xslutput 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>
<xsltherwise>
<xsl:apply-imports/>
</xsltherwise>
</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>
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"/>
<xslutput 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>
<xsltherwise>
<xsl:apply-imports/>
</xsltherwise>
</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>