Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Accessing elements with namespaces

Reply
Thread Tools

Accessing elements with namespaces

 
 
johkar
Guest
Posts: n/a
 
      03-13-2008
Given that all the nodes in my XML document have the "dsml" namespace,
what is the XSL syntax to access the elements or apply templates?
Below is a snippet:

<dsml:batchResponse xmlns:dsml="urnasis:names:tcSML:2:0:core"
xmlns="urnasis:names:tcSML:2:0:core" xmlnssd="http://www.w3.org/
2001/XMLSchema" xmlnssi="http://www.w3.org/2001/XMLSchema-instance">
<dsml:searchResponse>
<dsml:searchResultEntry>
<dsml:attr name="mail">
<dsml:value>(E-Mail Removed)</dsml:value>
</dsml:attr>
</dsml:searchResultEntry>
</dsml:batchResponse>
 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      03-13-2008
johkar wrote:
> Given that all the nodes in my XML document have the "dsml" namespace,
> what is the XSL syntax to access the elements or apply templates?
> Below is a snippet:
>
> <dsml:batchResponse xmlns:dsml="urnasis:names:tcSML:2:0:core"
> xmlns="urnasis:names:tcSML:2:0:core" xmlnssd="http://www.w3.org/
> 2001/XMLSchema" xmlnssi="http://www.w3.org/2001/XMLSchema-instance">
> <dsml:searchResponse>
> <dsml:searchResultEntry>
> <dsml:attr name="mail">
> <dsml:value>(E-Mail Removed)</dsml:value>
> </dsml:attr>
> </dsml:searchResultEntry>
> </dsml:batchResponse>


In the XSLT stylesheet you need to bind a prefix to the namespace URI
and use that prefix in XPath expressions and match patterns. Often the
same prefix as in the XML input is used but that is not necessary.
<xsl:stylesheet
xmlnssl="http://www.w3.org/1999/XSL/Transform"
version="1.0"
xmlns:dsml="urnasis:names:tcSML:2:0:core">

<xsl:template match="dsml:batchResponse">
...
</xsl:template>

</xsl:stylesheet>

--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
 
 
 
Joseph Kesselman
Guest
Posts: n/a
 
      03-13-2008
johkar wrote:
> Given that all the nodes in my XML document have the "dsml" namespace,
> what is the XSL syntax to access the elements or apply templates?


Define a prefix in your stylesheet which maps to that namespace, and use
that prefix in your XPaths, like so:

<xsl:stylesheet ... xmlns:dsml="urnasis:names:tcSML:2:0:core" ...>
...
<xsl:template match="dsml:batchResponse">
<xsl:apply-templates select="//dsml:value"/>
</xsl:template>
...

<xsl:stylesheet>

and so on.

Standard pointer to the many tutorials/articles on
http://www.ibm.com/xml, since this is a question that any decent XSLT
tutorial should have answered.

--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
 
Reply With Quote
 
johkar
Guest
Posts: n/a
 
      03-13-2008
On Mar 13, 10:38*am, Martin Honnen <(E-Mail Removed)> wrote:
> johkar wrote:
> > Given that all the nodes in my XML document have the "dsml" namespace,
> > what is the XSL syntax to access the elements or apply templates?
> > Below is a snippet:

>
> > <dsml:batchResponse xmlns:dsml="urnasis:names:tcSML:2:0:core"
> > xmlns="urnasis:names:tcSML:2:0:core" xmlnssd="http://www.w3.org/
> > 2001/XMLSchema" xmlnssi="http://www.w3.org/2001/XMLSchema-instance">
> > * *<dsml:searchResponse>
> > <dsml:searchResultEntry>
> > * * *<dsml:attr name="mail">
> > * * * * *<dsml:value>(E-Mail Removed)</dsml:value>
> > * * *</dsml:attr>
> > </dsml:searchResultEntry>
> > </dsml:batchResponse>

>
> In the XSLT stylesheet you need to bind a prefix to the namespace URI
> and use that prefix in XPath expressions and match patterns. Often the
> same prefix as in the XML input is used but that is not necessary.
> * *<xsl:stylesheet
> * * *xmlnssl="http://www.w3.org/1999/XSL/Transform"
> * * *version="1.0"
> * * *xmlns:dsml="urnasis:names:tcSML:2:0:core">
>
> * * *<xsl:template match="dsml:batchResponse">
> * * * * ...
> * * *</xsl:template>
>
> * *</xsl:stylesheet>


Thanks very much...and quick too.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Accessing the attributes of XML elements with namespaces matthewjbarr@gmail.com XML 2 02-11-2007 01:24 PM
XSLT: iterating all child elements and accessing homonymous childrenin sibling elements Gerald Aichholzer XML 2 06-27-2006 03:46 PM
Accessing namespaces referenced in codebehind of an ascx file newjazzharmony@hotmail.com ASP .Net 2 05-23-2006 06:13 PM
JDOM Children Elements and Namespaces gimme_this_gimme_that@yahoo.com XML 0 04-21-2005 12:15 AM
Matching elements that contain different namespaces Hugh Sparks XML 8 07-30-2004 04:58 PM



Advertisments