xsl-list
[Top] [All Lists]

Re: CLARIFICATION ON NAMESPACE

2004-05-26 22:28:32
You must include the namespace prefixe to the names for the elements.
In your example the title was not in the namespaces you intended.

Here you must use the namespace prefixes 

 <?xml-stylesheet type="text/xsl" href="main.xsl"?>
 <root>
     <head xmlns:fa="http://www.test.com/element-a";>
         <fa:title>I am in file 'fa'</fa:title>
     </head>
     <head xmlns:fb="http://www.test.com/element-b";>
         <fb:title>I am in file 'fb'</fb:title>
     </head>
 </root>

or use the default namespace like this. 

 <?xml-stylesheet type="text/xsl" href="main.xsl"?>
 <root>
     <head xmlns="http://www.test.com/element-a";>
         <title>I am in file 'fa'</title>
     </head>
     <head xmlns="http://www.test.com/element-b";>
         <title>I am in file 'fb'</title>
     </head>
 </root>


----- Original Message ----- 
From: "Arul Kumar" <arulxml(_at_)netscape(_dot_)net>
To: <xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
Sent: Thursday, May 27, 2004 5:36 AM
Subject: [xsl] CLARIFICATION ON NAMESPACE


Hello all,

Greetings

My xml having the root element called 'root', two child elements 'head', 
both the head element having the namespace declaration 'fa' and 'fb' 
respectively, and having the child called 'title'.

In my memory, some time ago I read about the namespace declaration as 
'The namespace declaration given for the current element is also valid 
for all children and descendants'. According to this, can I able to 
treat (in XSL) the 'title' element as 'fa:title' and 'fb:title'?

When I do so, in view the xml in IE, I couldn't see the expected result? 
Please find my XML and XSL appended below.

My XML (test.xml):

<?xml-stylesheet type="text/xsl" href="main.xsl"?>
<root>
    <head xmlns:fa="http://www.test.com/element-a";>
        <title>I am in file 'fa'</title>
    </head>
    <head xmlns:fb="http://www.test.com/element-b";>
        <title>I am in file 'fb'</title>
    </head>
</root>

My XSL (main.xsl):

<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
    xmlns="http://www.test.com/xml";
    xmlns:fa="http://www.test.com/element-a";
    xmlns:fb="http://www.test.com/element-b";>
<xsl:output method="html"/>
<xsl:template match="/">
<html>
    <body>
    <p style="color:red">FA: <xsl:value-of 
select="string(//*/*/fa:title)"/></p>
    <p style="color:blue">FB: <xsl:value-of 
select="string(//*/*/fb:title)"/></p>
    </body>
</html>
</xsl:template>
</xsl:stylesheet>

Please advice, how to achieve this? Or my understanding is wrong? Please 
share your valuable comments. Many thanks in advance.

Kind regards
Arul



--+------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--+--



<Prev in Thread] Current Thread [Next in Thread>