[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: namespace problem

Subject: Re: namespace problem
From: "Wolfgang Laun wolfgang.laun@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 5 Sep 2014 15:23:24 -0000
Re:  namespace problem
Hi Ruud,

I'm not sure what you misunderstood, but here's the XSLT that does what you
want. I've added a couple of comments to indicate what goes on where.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:transform i Ruud,version="2.0"
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   xmlns:xs="http://www.w3.org/2001/XMLSchema"
   exclude-result-prefixes="xs xsl">

  <xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes" />

  <xsl:template match="/">
    <!-- establish the default namespace for the created document -->
    <document xmlns="http://www.w3.org/1999/xhtml">
      <xsl:apply-templates/>
    </document>
  </xsl:template>

  <!-- match an element from the no-namespace -->
  <xsl:template xmlns="" match="p">
    <xsl:variable name='blip'>
      <xsl:apply-templates />
    </xsl:variable>

    <xsl:apply-templates select='$blip' mode='pass2' />
  </xsl:template>

  <!-- match another element from the no-namespace -->
  <xsl:template xmlns="" match="Char">
    <!-- element created here is in the no-namespace -->
    <char><xsl:apply-templates /></char>
  </xsl:template>

  <!-- match the element created during pass 1, still from the no-namespace
-->
  <xsl:template xmlns="" match='char' mode='#all'>
    <!-- element for the final document, to be in the (re-established)
xhtml-ish default namespace -->
    <c xmlns="http://www.w3.org/1999/xhtml"><xsl:apply-templates /></c>
  </xsl:template>
</xsl:transform>

Input:
<doc>
<p><Char>hello</Char><Char> there</Char></p>
</doc>

Output:
<?xml version="1.0" encoding="utf-8"?>
<document xmlns="http://www.w3.org/1999/xhtml">
   <c>hello</c>
   <c> there</c>
</document>

HTH
Wolfgang




On 4 September 2014 09:16, Ruud Grosmann r.grosmann@xxxxxx <
xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:

> Hi Wolfgang,
>
> thanks for your reaction
>
> On 09/03/14 17:37, Wolfgang Laun wolfgang.laun@xxxxxxxxx wrote:
>
>> You need to match a document that has elements <doc>, <p>, <Char> that are
>> in *no namespace*, where the name has no namespace name, just a locsl
>> name.
>> Your output document is supposed to be in the namespace "
>> http://www.w3.org/1999/xhtml", and you'd like to use the shortened
>> notation
>> known as *default namespace*. In the 2nd version of your XSLT you
>> introduce
>> a default namespace, and, sure enough, the matches written without a
>> prefix
>> aren't in the no namespace ghetto any more.
>>
>
> That puzzles me a bit, because templates p and Char *do* match. The
> difference is the char template, the char elements are now part of the
> documentnode in the blip variable.
> I tried to change the namespace of that documentnode, but up till now, I
> have not succeeded.
>
>
>  You may, however, at any time cancel the definition for the default
>> namespace by writing
>>
>>      xmlns=""
>>
>> and everything below that has no prefix hasn't a namespace name either.
>>
>>
> Assuming this has to be added to a template match, I tried this:
>
>   <xsl:template xmlns='' match='char' mode='#all'>
>     <c><xsl:apply-templates /></c>
>   </xsl:template>
>
> But that does not work either, nor when I change that to the xhtml
> namespace.
>
> Maybe I misunderstood you. Thanks for the explanation; I realize more and
> more it is essential to have a good understanding of namespaces...
>
> regards, Ruud

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.