473,796 Members | 2,628 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XSLT namespace selection (how)?

I am trying to transform an XML document (google base feed) where it's
root element falls within a namespace. Because of this namespace, my
simplistic XSL transformation doesn't (I'm guessing) match/select the
correct elements.

Can someone please explain the matching/selection (xpath?) syntax for
projecting some of the element's data such as <idand
<openSearch:tot alResults>?

The example google base feed is:

<?xml version='1.0'?>
<feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearc h='http://
a9.com/-/spec/opensearchrss/1.0/' xmlns:gm='http://base.google.com/ns-
metadata/1.0' xmlns:g='http://base.google.com/ns/1.0'
xmlns:batch='ht tp://schemas.google. com/gdata/batch'>
<updated>2007-05-25T18:56:07.358 Z</updated>
<openSearch:tot alResults>1</openSearch:tota lResults>
<openSearch:sta rtIndex>1</openSearch:star tIndex>
<openSearch:ite msPerPage>25</openSearch:item sPerPage>
<entry>
<id>foo1</id>
</entry><entry>
<id>foo2</id>
</entry>
</feed>

And a simplistic XSL attempting to select the <id>:

<?xml version='1.0'?>
<xsl:styleshe et xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
xmlns:feed='htt p://www.w3.org/2005/Atom'
version="1.0"
>
<xsl:template match="/">
<xsl:for-each select="feed:en try">
<xsl:value-of select="id" />
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Much appreciated. Thanks,

Jun 5 '07 #1
5 7307
* Queue wrote in comp.text.xml:
><xsl:templat e match="/">
<xsl:for-each select="feed:en try">
<xsl:value-of select="id" />
You have two errors here. The first is that feed:entry is not a child of
the root node, they are children of the feed:feed element. So you would
have to say e.g.

xsl:for-each select = 'feed:feed/feed:entry'

This is unlikely the best way, but this would work. Further, the <id>
element is also in the http://www.w3.org/2005/Atom namespace, so you
have to specify the prefix in the value-of aswell, i.e.

xsl:value-of select = 'feed:id'

The rule is quite simple, if what you want to refer to is in a namespace
you have to declare a prefix for the namespace and always specify the
prefix.
--
Björn Höhrmann · mailto:bj****@h oehrmann.de · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/
Jun 5 '07 #2
On Jun 5, 11:37 am, Bjoern Hoehrmann <bjo...@hoehrma nn.dewrote:
xsl:for-each select = 'feed:feed/feed:entry'
xsl:value-of select = 'feed:id'
Great, this works. Thank you. Thus for any element declared within a
namespace, in the corresponding XSL all elements within that hierarchy
must be prefixed?

What about the case in the example

<openSearch:tot alResults>1</openSearch:tota lResults>

Which is contained within the <feedelement (prefixed). I am sure I
can't simply do select="feed:op enSearch:totalR esults". What about
nested elements within namespaces?

Thank you again,

Jun 5 '07 #3
Queue wrote:
>Thus for any element declared within a
namespace, in the corresponding XSL all elements within that hierarchy
must be prefixed?
No. To match a namespaced name at any given point in an XPath, the path
must use a prefixed name at that point where the prefix is bound to the
correct namespace. So to match
<openSearch:tot alResults>1</openSearch:tota lResults>
directly, you would use:
select="opensea rch:totalResult s"

Or, if you needed to specify multiple steps to reach it, you would use
something like:
select="feed:fe ed/feed:entry/opensearch:tota lResults"

--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
Jun 5 '07 #4
On Jun 5, 1:43 pm, Joseph Kesselman <keshlam-nos...@comcast. net>
wrote:
select="opensea rch:totalResult s"
select="feed:fe ed/feed:entry/opensearch:tota lResults"
I just tried this from that XML example in the XSL below but I receive
no selection of the data? Shouldn't the whole openSearch prefix be
prefixed itself? Thanks for all the newbie help.

<?xml version='1.0'?>
<xsl:styleshe et xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
xmlns:openSearc h='http://a9.com/-/spec/opensearchrss/1.0/'
xmlns:gm='http://base.google.com/ns-metadata/1.0'
xmlns:g='http://base.google.com/ns/1.0'
xmlns:batch='ht tp://schemas.google. com/gdata/batch'
xmlns:feed='htt p://www.w3.org/2005/Atom'
version="1.0"
>
<xsl:template match="/">
<div>
<span>total1=<x sl:value-of select="openSea rch:totalResult s"/>
</span>
<span>total2= <xsl:value-of select="feed:fe ed/feed:entry/
openSearch:tota lResults"/</span>
<xsl:for-each select="feed:fe ed/feed:entry">
<pre>
<xsl:value-of select="feed:id " />
</pre>
</xsl:for-each>
</div>
</xsl:template>
</xsl:stylesheet>

Jun 5 '07 #5
* xailor wrote in comp.text.xml:
>On Jun 5, 1:43 pm, Joseph Kesselman <keshlam-nos...@comcast. net>
wrote:
> select="opensea rch:totalResult s"
select="feed:fe ed/feed:entry/opensearch:tota lResults"

I just tried this from that XML example in the XSL below but I receive
no selection of the data? Shouldn't the whole openSearch prefix be
prefixed itself? Thanks for all the newbie help.

<?xml version='1.0'?>
<xsl:styleshee t xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
xmlns:openSearc h='http://a9.com/-/spec/opensearchrss/1.0/'
xmlns:gm='http://base.google.com/ns-metadata/1.0'
xmlns:g='http://base.google.com/ns/1.0'
xmlns:batch='ht tp://schemas.google. com/gdata/batch'
xmlns:feed='htt p://www.w3.org/2005/Atom'
version="1.0"
>>
<xsl:templat e match="/">
<div>
<span>total1=<x sl:value-of select="openSea rch:totalResult s"/>
Again, here the context node is the document node which usually has a
single child node, the root element of the document, the <feedelement
in your example. 'openSearch:tot alResults' matches all openSearch:
totalResults elements that are a child of the context node, but there
is no such child.
<span>total2= <xsl:value-of select="feed:fe ed/feed:entry/
openSearch:tot alResults"/</span>
This would only match the first openSearch:tota lResults element, you
likely want this for each entry.
--
Björn Höhrmann · mailto:bj****@h oehrmann.de · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/
Jun 5 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2815
by: Stefan Siegl | last post by:
Hello, I am trying to learn XSLT to use it in another project. I start reading the book "Java and XSLT" and tried the examples and they are went quite fine (how suprising *g*). Then I tried to adopt these examples to my files. Unfortunately I did not work even though the styleSheet is very simple. Perhaps you can help me with it.
3
10799
by: Benjamin Hillsley | last post by:
Hi, I have a xml file that catalogs my cd and dvd collection, and I am currently writing a web page to access this catalog. I would like to include a selection box that lists the CD's by artist, and then have the XSLT select only what artist is chosen in the selection box. So far I have been able to create the selection box, and populate it with the artist's names. I have also created the <XSL:IF> statement that will
1
1681
by: Harry Zoroc | last post by:
I would like to treat an xsd Schema file as XML file and to display the targetNamespace and all the imports. That's it. But the following does not work. Why? I did not enter the stylesheet in the xsd file directly but tried to compute the output on the command line e.g. with xalan like: java net.sf.saxon.Transform -o myout.html myschema.xsd myxsltfile.xslt Using Saxon yields no better result. The produced myout.html contains all HTML...
4
8120
by: cyclops | last post by:
I'm trying to do XML + XSLT -> Another XML. The source XML contains multiple namespaces and XSLT will handle all possible tags under each name space. ----source---- <document xmlns="..." xmlns:a="..." xmlns:b=""> .... ----XSLT---- ....
4
9008
by: David S. Alexander | last post by:
How can I do simple subtraction in an XSLT. I want to read a few attribute values from an XML document, calculate their difference, and transform that value to an attribute in the XML output document. My original XML is, <Dates> <Birth Year="1966" />
1
2745
by: Nick | last post by:
I am working on a website for a client and one of their requirements was to have a mailing list. I decided to XSLT to transform "templates" to HTML so that editing was very easy and less time consuming. I keep getting the following error when I submit my email to their site. System.Xml.Xsl.XslTransformException: Cannot find the script or external object that implements prefix 'ext:MailingList'. at...
1
1883
by: Rajesh | last post by:
I am trying to pass the namespace, which is in my Original Message, to a Java method for further processing. In the original message the xmlns:xenc namespace is present. I make a call to Java function and pass the whole XML message along with tags and values. In my Java function when I tried to print the XML message which is receieved by the XSLT proc. it has omitted the xmlns:xenc namespace which is creating a problem in Java function for...
6
4343
by: kluge.wolfram | last post by:
Hi, i get stucked on a transformation problem using XSLT. What i need is to copy an XML Tree to an output XML without any automatic changes. Since i used <xsl:copyor <xsl:copy-ofthere occur unwanted side effects. For example i just copied a xml were several namespace declarations are present more than one time. Then the transformation do remove the declaration at the child nodes. Another funny automatism is - if i remove a node
0
10455
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10173
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10006
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9052
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7547
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6788
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5441
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5573
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.