Subject: [xsl] Identity transform (case conversion) From: "Mukul Gandhi" <gandhi.mukul@xxxxxxxxx> Date: Fri, 7 Jul 2006 22:26:45 +0530 |
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.
<?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>
<?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>
<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>
<?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.
<?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>
Regards, Mukul
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Serializing <script> elements, MrDemeanour | Thread | Re: [xsl] Identity transform (case , George Cristian Bina |
[xsl] OT: Advice on Oxygen XML Edit, omprakash . v | Date | [xsl] Selecting all repeated elemen, Jason Foster |
Month |