473,570 Members | 2,923 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XSL xmlns problem

6 New Member
Hi,

I have an xsl transform to convert xml into another (non-standard) data structure. All is fine until I have an xml file with xmlns atts and then all I get is the element contents output with none of the tagging that I have written in. Remove the xmlns atts from the xml and all is fine. I’ve tried adding in the xmlns from the xml into the xsl:stylesheet element of the xsl but get the same result. This is the same run on xmlspy and with xalan.

Can anyone point me in the direction of where I’m going wrong?

Thanks
E
May 15 '09 #1
11 6667
jkmyoung
2,057 Recognized Expert Top Contributor
You need to edit your xpaths to use the namespace.

eg, say your xpath is "/root/somenode/leaf/@id"
declare your namespace like xmlns:sns="www. google.ca"
your xpath then becomes: "/sns:root/sns:somenode/sns:leaf/@id"
May 15 '09 #2
eb621
6 New Member
Hi,

I may well be understanding this incorrectly... please see the dummy examples below

I though that this - xmlns="http://xml.dummy.com/schema/analytical"- would give some sort of default

If you run the xml as is through the xsl you don't get any of the (archaic) tagging in the xsl:text elements output but remove the xmlns atts from the document node of the xml and you do...

Still consfused I'm afraid.

Thanks for your help on this...

xml
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <?xml-stylesheet type="text/xsl" href="main-transform.xsl"?>
  3. <document xmlns:legis="http://xml.dummy.com/schema/legislation/act" xmlns:xlink="http://www.w3.org/TR/xlink/" xmlns:a="http://xml.dummy.com/schema/amendments" xmlns="http://xml.dummy.com/schema/analytical">
  4.     <title>Companies Act 1985</title>
  5.     <paragraph role="annotation">
  6.         <title>Note</title>
  7.         <para>For the registrar's index of company names see s. 714</para>
  8.     </paragraph>
  9. </document>
XSL
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:legis="http://xml.dummy.com/schema/legislation/act" xmlns:xlink="http://www.w3.org/TR/xlink/" xmlns:a="http://xml.dummy.com/schema/amendments" xmlns="http://xml.dummy.com/schema/analytical">
  3.  
  4.     <xsl:output method="text" omit-xml-declaration="yes" indent="no"/>
  5.     <xsl:strip-space elements="*"/> <!-- for xalan on pc -->
  6.  
  7.     <xsl:template match="/">
  8.         <xsl:apply-templates/>
  9.     </xsl:template>
  10.  
  11.     <xsl:template match="title">
  12.         <xsl:text>&lt;UN+&gt;</xsl:text>
  13.         <xsl:apply-templates/>
  14.         <xsl:text>&lt;UN-&gt;&lt;CR&gt;
  15. </xsl:text>
  16.     </xsl:template>
  17.  
  18.     <xsl:template match="paragraph">
  19.         <xsl:text>&lt;IT+&gt;</xsl:text>
  20.         <xsl:apply-templates/>    
  21.         <xsl:text>&lt;IT-&gt;&lt;CR&gt;
  22. </xsl:text>
  23.     </xsl:template>
  24.  
  25.     <xsl:template match="para">
  26.         <xsl:apply-templates/>    
  27.         <xsl:text>&lt;CR&gt;
  28. </xsl:text>
  29.     </xsl:template>
  30.  
  31. </xsl:stylesheet>
May 21 '09 #3
Dormilich
8,658 Recognized Expert Moderator Expert
Expand|Select|Wrap|Line Numbers
  1.     <xsl:template match="legis:title">
  2.         <xsl:text>&lt;UN+&gt;</xsl:text>
  3.         <xsl:apply-templates/>
  4.         <xsl:text>&lt;UN-&gt;&lt;CR&gt;
  5. </xsl:text>
  6.     </xsl:template>
this is what jkmyoung was talking about. in any XPath (i.e. also in the match attribute) the appropriate namespace has to be added. otherwise the default namespace ("" (empty namespace)) is used and you get no match.
May 21 '09 #4
jkmyoung
2,057 Recognized Expert Top Contributor
Just declaring it there is not enough. The xsl still looks for these elements with the default empty namespace. You need to declare the namespace with a prefix, eg and then add the prefix before the element name in each of the templates:

eg, like:
xmlns:rr="http://xml.dummy.com/schema/analytical"

<xsl:template match="rr:title ">

It is confusing, and I remember trying to do it the same way when I started.
May 21 '09 #5
eb621
6 New Member
I tried this (changing the default name space to a "z" namespace) and still have the problem (below)

My understanding is that although it's convention to use the schema location for the name space it doesn't actually go off and look at the schema. I have a merry band of schemas that make the rules (64 to date) but this should be irrelevant?! In any case the dummy code I've given below is too simple for this to be an issue.

Any further thoughts? - thanks for your input...

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <?xml-stylesheet type="text/xsl" href="main-transform.xsl"?>
  3. <document xmlns:legis="http://xml.dummy.com/schema/legislation/act" xmlns:xlink="http://www.w3.org/TR/xlink/" xmlns:a="http://xml.dummy.com/schema/amendments" xmlns:z="http://xml.dummy.com/schema/analytical">
  4.     <title>Companies Act 1985</title>
  5.     <paragraph role="annotation">
  6.         <title>Note</title>
  7.         <para>For the registrar's index of company names see s. 714</para>
  8.     </paragraph>
  9. </document>
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:legis="http://xml.dummy.com/schema/legislation/act" xmlns:xlink="http://www.w3.org/TR/xlink/" xmlns:a="http://xml.dummy.com/schema/amendments" xmlns:z="http://xml.dummy.com/schema/analytical">
  3.  
  4.     <xsl:output method="text" omit-xml-declaration="yes" indent="no"/>
  5.     <xsl:strip-space elements="*"/> <!-- for xalan on pc -->
  6.  
  7.     <xsl:template match="/">
  8.         <xsl:apply-templates/>
  9.     </xsl:template>
  10.  
  11.     <xsl:template match="z:title">
  12.         <xsl:text>&lt;UN+&gt;</xsl:text>
  13.         <xsl:apply-templates/>
  14.         <xsl:text>&lt;UN-&gt;&lt;CR&gt;
  15. </xsl:text>
  16.     </xsl:template>
  17.  
  18.     <xsl:template match="z:paragraph">
  19.         <xsl:text>&lt;IT+&gt;</xsl:text>
  20.         <xsl:apply-templates/>    
  21.         <xsl:text>&lt;IT-&gt;&lt;CR&gt;
  22. </xsl:text>
  23.     </xsl:template>
  24.  
  25.     <xsl:template match="z:para">
  26.         <xsl:apply-templates/>    
  27.         <xsl:text>&lt;CR&gt;
  28. </xsl:text>
  29.     </xsl:template>
  30.  
  31. </xsl:stylesheet>
May 22 '09 #6
jkmyoung
2,057 Recognized Expert Top Contributor
Lol, by changing the namespace prefix in your source xml, you've moved all those elements back into the default namespace, (because there is no element with just xmlns="somethin g.com"

Easiest change is to change it to xmlns="http://xml.dummy.com/schema/analytical" in ONLY your source xml. Another possible way to fix it is to prefix z: before each of the elements in your source xml (waste of time).
May 25 '09 #7
eb621
6 New Member
Hi again,

I tried that but that didn't work ...! I've played around with a few combos of what I had (just for that namespace) and it works if I remove it completely from the xml. It’s also OK if change it to xmlns:z in the xml and just xmlns in the xsl. It doesn’t seem to mind one way or the other what I have in the xsl.

This means that I’ll have to do a bit or pre-processing to remove this from the xml, which I was hoping to avoid. Are there any other alternatives? Will I have any potential problems of I do remove this?

Thanks for this
May 26 '09 #8
Dormilich
8,658 Recognized Expert Moderator Expert
do you use any of the namespaces in your XML (despite defining them)?

like
Expand|Select|Wrap|Line Numbers
  1. <namepace:element>
  2. <!-- or -->
  3. <element xmlns="namespace-uri">
May 26 '09 #9
eb621
6 New Member
It's early days and the datamodel is still being written and I have precious little sample data to go on but I'd say yes - things like the samples below are what I'm seeing...

Expand|Select|Wrap|Line Numbers
  1. <xref  xmlns:xlink="http://www.w3.org/TR/xlink/" xlink:type="simple" link:href="p4600B/>
  2.  
  3. <graphic xmlns:ns1=http://xml.dummy.com/schema/lcr ns1:id="I3393df708bb611dcbdd2b4d3d31e5c5e"><caption>transport A to B</caption></graphic>
May 26 '09 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

1
4127
by: Chris Bedford | last post by:
Hi: this question has been driving me crazy. would be grateful for any help. I am writing a version of the identity transformation to filter some documents (they happen to be wsdl docs). My problem is that for just about every element in the output document all of the namespace defintions defined in my top
1
5396
by: jorgen.wahlund | last post by:
Hi I have problems with transforming a xml document with Xalan and javax.xml.Transformer. Following xsl is used: <xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform' xmlns:xalan="http://xml.apache.org/xslt" xmlns:java="java"
4
8958
by: Gismo | last post by:
I have got file raport.rld which is an XML file generated by MS Reporting Services. The problem is: in this file are tags from two different namespaces xmlns="http://schemas.microsoft.com/sqlserver/reporting/2003/10/reportdefini tion" xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner"
4
3584
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# code is, // Create an XSLT transform object XslTransform xslTransform = new XslTransform(); // Load the stylesheet
1
1875
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...
0
2781
by: jts2077 | last post by:
I am trying to create a large nested XML object using E4X methods. The problem is the, the XML I am trying to create can only have xmlns set at the top 2 element levels. Such as: <store xmlns="http://www.store.com/xml/1.1.0.0/impex/catalog"> <product sku="10050-1653" xmlns="http://www.store.com/xml/1.1.0.0/impex/catalog"> ...
3
1884
by: Gary Stephenson | last post by:
I am endeavouring to use .NET v2.0 XML facilities to "roundtrip" reading and writing XML documents - i.e. to end up with _exactly_ what I started with, but I can't seem to figure out how to get an XMLReader to report "xmlns" attributes. It seems to report an "xmlns='MyDefaultURI'" with incorrect data, and doesn't appear to report ...
3
7259
by: Keith Patrick | last post by:
I'm doing some document merging where I want to bring in an XmlDocument and import its document element into another document deeper in its tree. However, when serializing my underlying objects, .Net likes to add these namespaces: <RootNode xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">...
4
4802
by: BorisBoshond | last post by:
Hi all, Hope someone is able and willing to help me with following problem. I received a xsd file from another company, our company i supposed to return xml based on that xsd. Problem is that I don't really understand how these namespace work in xml. (I am however aware of what problems namespaces solve) I'm not even sure if the provided...
8
30732
by: nwbabcock | last post by:
I'm using XmlSerializer in C# to deserialize an xml into classes. First I generated the code from the schema using xsd.exe The error I recieve is: Exception:There is an error in XML document (2, 2). Inner Exception: <applications xmlns='urn:xmlns:COMMONCENSUS:CommonFormat:IMSchem a'> was not expected. I've read numerous threads and realize...
0
7726
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7948
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. ...
0
8150
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6329
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...
1
5523
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...
0
5247
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...
0
3671
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2131
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1238
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.