473,237 Members | 1,405 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,237 software developers and data experts.

XSL problem matching node containing xmlns attribute

Hi there,

Apologies if I'm posting to the wrong group; this one looked to be the
best match.

I'm having trouble writing a bit of XSL/XPATH and wondered if someone
would please shed some light. My XML is generated by InfoPath and of
the structure:

....
<my:Alpha>
<my:Beta>
<my:Gamma>
<div xmlns="http://www.w3.org/1999/xhtml">one line of text</div>
<div xmlns="http://www.w3.org/1999/xhtml">another one</div>
</my:Gamma>
</my:Beta>
<my:Beta>
<my:Gamma>just the one line here
</my:Gamma>
</my:Beta>
</my:Alpha>
....

Note the my:Gamma node - sometimes it will contain divs separating
pieces of text, other times just text. In my XSL I'm trying to test
whether my:Gamma contains divs (if it does, then I can get value-of
div, otherwise I can just get value-of my:Gamma).

I'm trying to use the below construct:

<xsl:choose>
<xsl:when test="div">
...
</xsl:when>
<xsl:otherwise>
...
</xsl:otherwise>
</xsl:choose>

This works if I get rid of the xmlns="http://www.w3.org/1999/xhtml"
from the div tags, but I can't seem to write a valid test condition in
the xsl:when that will find the full <div
xmlns="http://www.w3.org/1999/xhtml"tag. I thought <xsl:when
test="div[@*]"might work but it doesn't seem to, leading me to think
that 'xmlns' isn't classified as an attribute as such. Maybe it's
blindingly obvious but I haven't been able to find an answer!

Many thanks in advance.

Jan 22 '07 #1
4 3883
clover2411 wrote:
<my:Gamma>
<div xmlns="http://www.w3.org/1999/xhtml">one line of text</div>
<div xmlns="http://www.w3.org/1999/xhtml">another one</div>
</my:Gamma>
<xsl:choose>
<xsl:when test="div">
<xsl:when test="xhtml:div" xmlns:xhtml="http://www.w3.org/1999/xhtml">
Usually you will put the namespae declaration
xmlns:xhtml="http://www.w3.org/1999/xhtml" on the xsl:stylesheet element.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jan 22 '07 #2
clover2411 <cl********@gmail.comwrote:
>
This works if I get rid of the xmlns="http://www.w3.org/1999/xhtml"
from the div tags, but I can't seem to write a valid test condition in
the xsl:when that will find the full <div
xmlns="http://www.w3.org/1999/xhtml"tag. I thought <xsl:when
test="div[@*]"might work but it doesn't seem to, leading me to think
that 'xmlns' isn't classified as an attribute as such. Maybe it's
blindingly obvious but I haven't been able to find an answer!
I think that's a question of name space

add to your <xsl:stylesheet version ...
the following :

xmlns:h="http://www.w3.org/1999/xhtml">

don't put xmlns="..." in your div tags.

but rather for example :

<xsl:when test="//h:div[@foo = 'bar]">
[...]

you'll have to prefix all xhtml element with h:
--
Artaban de Mde
Jan 22 '07 #3
Thanks very much for your replies, I've used the below suggestion which
works nicely (and put the namespace declaration on the xsl:stylesheet
element). Makes sense now I see it! :-)
<xsl:when test="xhtml:div" xmlns:xhtml="http://www.w3.org/1999/xhtml">

Usually you will put the namespae declaration
xmlns:xhtml="http://www.w3.org/1999/xhtml" on the xsl:stylesheet element.
Not sure why InfoPath generates div tags with namespace declarations on
them in the middle of a form though, it'd be easier if it didn't!

Jan 23 '07 #4

clover2411 wrote:
Not sure why InfoPath generates div tags with namespace declarations on
them in the middle of a form though, it'd be easier if it didn't!
No, it will be _exactly_ as easy to work with them, however they
appear. It's fundamental to XML that these namespacing rules don't care
where the attribute appears, they just care what's in scope.

How you code your XSLT is a separate problem. IMHE, always place your
own namespaces on the XSLT root xsl:stylesheet element and always use
an explicit namespace prefix, not the default. Although it's
technically possible to do it the other way, it's not humanly possible
to understand the source.

Jan 23 '07 #5

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

Similar topics

0
by: Carl | last post by:
I want to create a generic xslt that would take xml input like: ########################################################################## <?xml version="1.0" encoding="utf-8" ?>...
7
by: Rolf Kemper | last post by:
Dear All, somehow I remember that such or similar question was discussed already somewhere. But I can't find it anymore. I have a template calling itself. As long it goes deeper into the...
2
by: Rick | last post by:
I have an XML document that is generated from Infopath, I need to change the value of a namespace that is defined in a node in the form: <xsf:xDocumentClass "xmlns:my=valuehere">. when i navigate...
0
by: Martin | last post by:
Hi, I would appreciate some help with creating an xml node in a document and automatically setting the default namespace The code below loads an xmnldocument with a default namespace --...
4
by: David S. Alexander | last post by:
I am trying to transform XML to XML using an XSLT in C#, but the root node of my XML is not being matched by the XSLT if it has an xmlns attribute. Am I handling my namespaces incorrectly? My C#...
2
by: RichardHatcher.com | last post by:
I am writing C code using xpath to extract some data from a XML document. The file uses namespaces, but the name spaces are all listed in the root node of the file as attributes. I want to...
4
by: patrizio.trinchini | last post by:
Hi all, I'm new to XSLT and maybe my problem have a very trivial answer, but I need an expert that point me in the right direction. What I would obtain is to remove all the elements that have a...
1
by: Tedros.G | last post by:
Hi I have an attribute the appears in both the root node and child node for example, below the attribute VERSION appears in the rood node (PRODMSG ) and a child node (OPERATION ) ================...
11
by: =?Utf-8?B?TTFpUw==?= | last post by:
I’m trying to add the following attributes (xmlns:xsi and xsi:type) to a node (Grantee) like the following: <Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="Group">...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.