XML.com: XML From the Inside Out

XML.comWebServices.XML.comO'Reilly Networkoreilly.com
  Articles | Weblogs | Newsletter | Safari Bookshelf
advertisement

Article:
 Trickledown Namespaces?
Subject: Question on namespaces
Date: 2004-08-09 16:35:50
From: cord_thomas

I am trying to create an XSLT transform for a jabber-produced file and have namespace problem that i believe this article addresses, but i cannot figure out the answer. Following are snips of the xml and my attempted xslt - where am i going wrong:


<xdb>
<foo xdbns="jabber:jud:users" xmlns="jabber:jud:users">
<item jid="some@im.rand.org">
<key/>
<name>a person</name>
<first>a</first>
<last>person</last>
<nick/>
<email/>
</item>
<foo>
<xdb>


XSLT:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ja="jabber:jud:users">
<xsl:output method="html"/>
<xsl:param name="i_eid"/>
<xsl:template match="/">
<HTML>
<HEAD> <LINK REL="stylesheet" TYPE="text/css" HREF="css/tipic.css"/>
</HEAD>
<BODY>
<table class="tbb">
<tr class="trIM">
<td class="thIM" width="220">IM UserName</td>
<td class="thNick" width="220">Nick Name</td>
</tr>
<xsl:apply-templates select="*/ja:foo/item"/>
</table>
</BODY>
</HTML>
</xsl:template>


<xsl:template match="ja:item">
<tr>
<td>
<xsl:value-of select="@jid"/>
</td>
<td>
<xsl:value-of select="nick"/>
</td>
</tr>
</xsl:template>
</xsl:stylesheet>


I am not clear on:
1 - the xpath relationship between the match name i put in under apply-templates, and the one i put in under the template match
2 - where i specify my ja: namespace prefix


This XSLT results in no data -


if i take out the jabber xmlns declaration in the source XML file, my XSLT transforms nicely, but i have no control over the XML source file.


Previous Message Previous Message   Next Message No Next Message


Titles Only Titles Only Newest First
  • Question on namespaces
    2005-01-06 12:55:47 mrylander@gmail.com [Reply]


    Just make the change below to your "xsl:apply-templates" line:


    <xsl:apply-templates select="*/ja:foo/ja:item"/>


    Because the jabber doc has a default namespace you need to provide a prefix in the XSLT, which you do. But you need to use that prefix on all elements in the default namespace, which includes the 'item' elements.


    Hope that helps!

Sponsored By:


Contact Us | Our Mission | Privacy Policy | Advertise With Us | | Submissions Guidelines
Copyright © 2008 O'Reilly Media, Inc. | (707) 827-7000 / (800) 998-9938