Subject: Re: [xsl] Identity transform (case conversion) From: "Mukul Gandhi" <gandhi.mukul@xxxxxxxxx> Date: Sat, 8 Jul 2006 00:11:03 +0530 |
Hi George, I have few more doubts..
The template matching elements can be further simplified to (Its slightly different than yours):
<xsl:template match="*"> <xsl:element name="{translate(name(), $small, $caps)}"> <xsl:variable name="nsHolder"> <test> <xsl:for-each select="current()//namespace::*[not(name()='xml')]"> <xsl:attribute name="{translate(name(), $small, $caps)}:dummy{position()}" namespace="{translate(., $small, $caps)}"></xsl:attribute> </xsl:for-each> </test> </xsl:variable> <xsl:copy-of select="exslt:node-set($nsHolder)/test/namespace::*"/> <xsl:apply-templates select="@*"/> <xsl:apply-templates/> </xsl:element> </xsl:template>
Also, you have written a predicate [not(name()='xml')]
I observed, that the namespace nodes of elements contain a special namespace xmlns:xml="http://www.w3.org/xml/1998/namespace" (as reported by Saxon). To suppress this in the output, you have used this predicate.
But this predicate doesn't work as expected, with MSXML. MSXML outputs xmlns:auto-ns1="http://www.w3.org/xml/1998/namespace" in the absence of this predicate.
Probably we need to write the above predicate as [not(name()='xml') or not(name()='auto-ns1')] to cater to both Saxon and MSXML.
I have a related question: What is the purpose of namespace http://www.w3.org/xml/1998/namespace ?
Regards, Mukul
Hi Mukul,
You need the node-set extension I think. Change your template that matches elements like below:
<xsl:template match="*"> <xsl:element name="{translate(name(), $small, $caps)}" namespace="{translate(namespace-uri(), $small, $caps)}"> <xsl:variable name="currentNamepsace" select="namespace-uri()"/> <xsl:variable name="nsHolder"> <test> <xsl:for-each select="current()//namespace::*[not(.=$currentNamepsace) and not(name()='xml')]" > <xsl:attribute name="{translate(name(), $small, $caps)}:dummy{position()}" namespace="{translate(., $small, $caps)}"></xsl:attribute> </xsl:for-each> </test> </xsl:variable>
<xsl:copy-of select="exslt:node-set($nsHolder)/test/namespace::*"/> <xsl:apply-templates select="@*"/> <xsl:apply-templates/> </xsl:element> </xsl:template>
and add xmlns:exslt="http://exslt.org/common" exclude-result-prefixes="exslt" on the stylesheet element.
Basically you need to create new namespace nodes and copy them instead of the old namespaces and also you need to change the namespace of the created elements and attributes (so you have to change accordingly the template that handles your attributes).
Best Regards, George --------------------------------------------------------------------- George Cristian Bina <oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger http://www.oxygenxml.com
Mukul Gandhi wrote: > Hello All, > I am trying to write a XSLT stylesheet (I am seeking both 1.0 and > 2.0 solutions. If extensions are unavoidable, I can use them) which > will take as input any XML document, and produce as output, a XML > document which is an identity of the input (i.e. what is produced by > the identity transform). But the condition is: all the letters (a-z) > anywhere in source XML should change from small case to capitals. > > for e.g. > > this source XML: > > <?xml version="1.0" ?> > <!-- this is a comment --> > <?pqr x="do-something" ?> > <author xmlns:a="xyz" xmlns:b="pqr"> > <person age="30"> by <FirstName>Jane</FirstName> > <LastName>Doe</LastName>, > </person> > </author> > > should transform to: > > <?xml version="1.0" encoding="UTF-8"?> > <!-- THIS IS A COMMENT --> > <?PQR X="DO-SOMETHING" ?> > <AUTHOR xmlns:A="XYZ" xmlns:B="PQR"> > <PERSON AGE="30"> BY <FIRSTNAME>JANE</FIRSTNAME> > <LASTNAME>DOE</LASTNAME>, > </PERSON> > </AUTHOR> > > Here is my attempt: > > <xsl:stylesheet version="1.0" > xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> > > <xsl:output method="xml" indent="yes" /> > > <xsl:variable name="small" select="'abcdefghijklmnopqrstuvwxyz'" /> > <xsl:variable name="caps" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" /> > > <xsl:template match="*"> > <xsl:element name="{translate(name(), $small, $caps)}"> > <xsl:copy-of select="current()//namespace::*" /> > <xsl:apply-templates select="@*" /> > <xsl:apply-templates /> > </xsl:element> > </xsl:template> > > <xsl:template match="text()"> > <xsl:value-of select="translate(., $small, $caps)" /> > </xsl:template> > > <xsl:template match="@*"> > <xsl:attribute name="{translate(name(), $small, > $caps)}"><xsl:value-of select="translate(., $small, $caps)" > /></xsl:attribute> > </xsl:template> > > <xsl:template match="processing-instruction()"> > <xsl:processing-instruction name="{translate(name(), $small, > $caps)}"><xsl:value-of select="translate(., $small, $caps)" > /></xsl:processing-instruction> > </xsl:template> > > <xsl:template match="comment()"> > <xsl:comment><xsl:value-of select="translate(., $small, $caps)" > /></xsl:comment> > </xsl:template> > > </xsl:stylesheet> > > This stylesheet produces output: > > <?xml version="1.0" encoding="UTF-8"?> > <!-- THIS IS A COMMENT --> > <?PQR X="DO-SOMETHING" ?> > <AUTHOR xmlns:a="xyz" xmlns:b="pqr"> > <PERSON AGE="30"> BY <FIRSTNAME>JANE</FIRSTNAME> > <LASTNAME>DOE</LASTNAME>, > </PERSON> > </AUTHOR> > > Everything else is fine, except the namespace handling. Their case is > not getting converted. What needs to be done for this? > > Another questions is: > The above output gets produced identically by Saxon 8.7.3 and MSXML > 4.0. But with Xalan-J 2.7.0, namespaces are not getting generated in > the output. > > Xalan produces output: > > <?xml version="1.0" encoding="UTF-8"?> > <!-- THIS IS A COMMENT --> > <?PQR X="DO-SOMETHING" ?> > > <AUTHOR> > <PERSON AGE="30"> BY <FIRSTNAME>JANE</FIRSTNAME> > <LASTNAME>DOE</LASTNAME>, > </PERSON> > </AUTHOR> > > Is this a Xalan bug? > > Regards, > Mukul
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Identity transform (case , Mukul Gandhi | Thread | RE: [xsl] Identity transform (case , Michael Kay |
Re: [xsl] OT: Advice on Oxygen XML , Chad Chelius | Date | RE: [xsl] transform fails with para, Michael Kay |
Month |