Re: [xsl] Identity transform (case conversion)

Subject: Re: [xsl] Identity transform (case conversion)
From: "Mukul Gandhi" <gandhi.mukul@xxxxxxxxx>
Date: Sat, 8 Jul 2006 21:45:38 +0530
Thanks Dimitre for the clarifications..

Here is the code which doesn't work fine with MSXML4.

This stylesheet:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";

xmlns:msxsl="urn:schemas-microsoft-com:xslt"
                                          exclude-result-prefixes="msxsl">

<xsl:output method="xml" indent="yes" encoding="UTF-8" />

  <xsl:variable name="small" select="'abcdefghijklmnopqrstuvwxyz'" />
  <xsl:variable name="caps" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" />

  <xsl:template match="*">
    <xsl:element name="{translate(name(), $small, $caps)}">
      <xsl:variable name="nsHolder">
        <test>
          <xsl:for-each select="namespace::*">
            <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="msxsl:node-set($nsHolder)/test/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)}"
namespace="{translate(namespace-uri(), $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>

When applied to this XML:

<?xml version="1.0" ?>
<!-- this is a comment -->
<?pqr x="do-something" ?>
<author xmlns:a="xyz" xmlns:b="pqr">
<person a:age="30"> by <FirstName>Jane</FirstName>
<LastName>Doe</LastName>,
</person>
</author>

produces output:

<?xml version="1.0" encoding="UTF-8"?>
<!-- THIS IS A COMMENT -->
<?PQR X="DO-SOMETHING" ?>
<AUTHOR xmlns:auto-ns1="HTTP://WWW.W3.ORG/XML/1998/NAMESPACE";
xmlns:A="XYZ" xmlns:B="PQR">
<PERSON A:AGE="30"> BY <FIRSTNAME>JANE</FIRSTNAME>
<LASTNAME>DOE</LASTNAME>,
</PERSON>
</AUTHOR>

Regards,
Mukul

On 7/8/06, Dimitre Novatchev <dnovatchev@xxxxxxxxx> wrote:
> Why at all the namespace, http://www.w3.org/xml/1998/namespace is part
> of node-set namespace::*. I am not sure, but does it relate to the XML
> Namespaces spec? (you hinted this in your previous answers)
>


How do you expect otherwise to be able to use an "xml:lang" attribute and a few more in this namespace without explicitly specifying the xml namespace?

So, the answer to your question is that this is a convenient default.

From the XML Namespace errata:

"Namespace constraint: Reserved Prefixes and Namespace Names

The prefix xml is by definition bound to the namespace name
http://www.w3.org/XML/1998/namespace. It may, but need not, be
declared, and must not be bound to any other namespace name. No other
prefix may be bound to this namespace name."

Note also that the namespace-uri used in your code is different from
the namespace-uri for the xml namespace -- as others advised this
answers your first question.

Could you send me the code, which causes MSXML4 to produce non-"xml"
bindings to the xml namespace uri?


-- Cheers, Dimitre Novatchev --------------------------------------- Truly great madness cannot be achieved without significant intelligence.

Current Thread