473,395 Members | 1,554 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,395 software developers and data experts.

Prefix problem with XML/XSL

I'm experiencing the following problem

The source xml file uses a prefix (wpl:) and look like this (shortened):
-----------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<wpl:Destinations xmlns:wpl="www.sapportals.com/portal/landscape"
xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
xsi:schemaLocation="wpl_jco_destionations_v10.xsd" >

<wpl:Destination name="SAP_R3_Financials_DEV200">
<wpl:SYSTEM>ZSECDS1200</wpl:SYSTEM>
<wpl:MSHOST>secacsap</wpl:MSHOST>
<wpl:R3NAME>DS1</wpl:R3NAME>
<wpl:CLIENT>200</wpl:CLIENT>
</wpl:Destination>
-----------------------------------------------------------------
The xsl file i created loos like this:
----------------------------------------------------------------
<?xml version="1.0" ?>
<wpl:stylesheet xmlns:wpl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

<wpl:output method="text"/>

<wpl:template match="Destination">
<wpl:value-of select="@name"/>
</wpl:template>

</wpl:stylesheet>
-------------------------------------------------------------------

I then run

xalan -o output.txt jcoDestinations.xml jcoDestinations.xsl

I would expect the output to be

SAP_R3_Financials_DEV200

however the output is:
ZSECDS1200
secacsap
DS1
200
I removed all the "wpl:" from the source, changed the xls to use "xsl"
rather than "wpl". This produces the expected output.

Is this a bug, or am I doing somthing wrong?
Regards
Jacques
Jul 20 '05 #1
3 4932
Jacques wrote:
I'm experiencing the following problem

The source xml file uses a prefix (wpl:) and look like this (shortened):
-----------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<wpl:Destinations xmlns:wpl="www.sapportals.com/portal/landscape"
xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
xsi:schemaLocation="wpl_jco_destionations_v10.xsd" >

<wpl:Destination name="SAP_R3_Financials_DEV200">
<wpl:SYSTEM>ZSECDS1200</wpl:SYSTEM>
<wpl:MSHOST>secacsap</wpl:MSHOST>
<wpl:R3NAME>DS1</wpl:R3NAME>
<wpl:CLIENT>200</wpl:CLIENT>
</wpl:Destination>
-----------------------------------------------------------------
The xsl file i created loos like this:


maybe a tiny misunderstanding

there's nothing wrong in your stylesheet (that is to say that it is a
correct stylesheet, although it doesn't produce the expected result)

however, your template doesn't handle elements from your xml source,
because you have to define a xmlns declaration with a prefix bound to
your data; as usually, the xslt namespace is bound to xsl, i recommend
to use the prefix xsl for the xslt namespace, and wpl for your own datas :

<?xml version="1.0" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:wpl="www.sapportals.com/portal/landscape"
version="1.0">

<xls:output method="text"/>

<xsl:template match="wpl:Destination">
<xsl:value-of select="@name"/>
</xsl:template>

</xsl:stylesheet>

you can see above that wpl:Destination matches the appropriate element
because the prefix is bound to the same uri (using the same prefix is
convenient but not mandatory)

the xsl prefix is bound to the uri that correspond to xslt, and will be
handled by your xslt processor

notice that unprefixed attributes are never bound to a namespace uri, so
one can safely use @name

what counts : only the univeral name, that consists of the namespace uri
and the local name (the name without the prefix); consider that a prefix
is just an alias, that is neutral

have a look at the namespace specification : a very little spec that
have a huge major importance in xml technologies

--
Cordialement,

///
(. .)
-----ooO--(_)--Ooo-----
| Philippe Poulard |
-----------------------
Jul 20 '05 #2
Jacques wrote:
I'm experiencing the following problem

The source xml file uses a prefix (wpl:) and look like this
(shortened):
-----------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?> <wpl:Destinations
xmlns:wpl="www.sapportals.com/portal/landscape"
xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
xsi:schemaLocation="wpl_jco_destionations_v10.xsd" >

<wpl:Destination name="SAP_R3_Financials_DEV200">
<wpl:SYSTEM>ZSECDS1200</wpl:SYSTEM>
<wpl:MSHOST>secacsap</wpl:MSHOST>
<wpl:R3NAME>DS1</wpl:R3NAME>
<wpl:CLIENT>200</wpl:CLIENT>
</wpl:Destination>
-----------------------------------------------------------------
The xsl file i created loos like this:
----------------------------------------------------------------
<?xml version="1.0" ?>
<wpl:stylesheet xmlns:wpl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

<wpl:output method="text"/>

<wpl:template match="Destination">
<wpl:value-of select="@name"/>
</wpl:template>

</wpl:stylesheet>
-------------------------------------------------------------------

I then run

xalan -o output.txt jcoDestinations.xml jcoDestinations.xsl

I would expect the output to be

SAP_R3_Financials_DEV200

however the output is:
ZSECDS1200
secacsap
DS1
200
I removed all the "wpl:" from the source, changed the xls to use "xsl"
rather than "wpl". This produces the expected output.

Is this a bug, or am I doing somthing wrong?


The prefix is not important for namespace resolution. The namespace uri
is. In your xml file, all the elements are in the
www.sapportals.com/portal/landscape namespace, which your style sheet
doesn't know anything about.

Jul 20 '05 #3
Thank you for a very informative explanation, as well as a practical
solution.
It works now, and I understand why.

Regards

"Philippe Poulard" <Ph****************@SPAMsophia.inria.fr> wrote in message
news:cb**********@news-sop.inria.fr...
Jacques wrote:
I'm experiencing the following problem

The source xml file uses a prefix (wpl:) and look like this (shortened):
-----------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<wpl:Destinations xmlns:wpl="www.sapportals.com/portal/landscape"
xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
xsi:schemaLocation="wpl_jco_destionations_v10.xsd" >

<wpl:Destination name="SAP_R3_Financials_DEV200">
<wpl:SYSTEM>ZSECDS1200</wpl:SYSTEM>
<wpl:MSHOST>secacsap</wpl:MSHOST>
<wpl:R3NAME>DS1</wpl:R3NAME>
<wpl:CLIENT>200</wpl:CLIENT>
</wpl:Destination>
-----------------------------------------------------------------
The xsl file i created loos like this:


maybe a tiny misunderstanding

there's nothing wrong in your stylesheet (that is to say that it is a
correct stylesheet, although it doesn't produce the expected result)

however, your template doesn't handle elements from your xml source,
because you have to define a xmlns declaration with a prefix bound to
your data; as usually, the xslt namespace is bound to xsl, i recommend
to use the prefix xsl for the xslt namespace, and wpl for your own datas :

<?xml version="1.0" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:wpl="www.sapportals.com/portal/landscape"
version="1.0">

<xls:output method="text"/>

<xsl:template match="wpl:Destination">
<xsl:value-of select="@name"/>
</xsl:template>

</xsl:stylesheet>

you can see above that wpl:Destination matches the appropriate element
because the prefix is bound to the same uri (using the same prefix is
convenient but not mandatory)

the xsl prefix is bound to the uri that correspond to xslt, and will be
handled by your xslt processor

notice that unprefixed attributes are never bound to a namespace uri, so
one can safely use @name

what counts : only the univeral name, that consists of the namespace uri
and the local name (the name without the prefix); consider that a prefix
is just an alias, that is neutral

have a look at the namespace specification : a very little spec that
have a huge major importance in xml technologies

--
Cordialement,

///
(. .)
-----ooO--(_)--Ooo-----
| Philippe Poulard |
-----------------------

Jul 20 '05 #4

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

Similar topics

1
by: Holger Joukl | last post by:
Hi there, 2 questions regarding build/installation issues: 1. In the python 2.3.3 setup.py script, the detect_modules method of class PyBuildExt contains the following code: 253 if...
1
by: Romeo Disca | last post by:
Hello newsgroup, i'm new to xml - what's wrong with this piece code here? i have these two files: test.xml ---- <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE a SYSTEM "test.ent"
4
by: Krishna Tulasi via .NET 247 | last post by:
Hi, I am having trouble with creation of XML programmatically using .NET. Specifically Im trying to create an element which looks like below and insert into an existing xml doc: <Worksheet...
4
by: BizTalk Benjamin | last post by:
Hi, I have an XmlDocument loaded from a memory stream. I set the document element prefix in this way XmlElement e = xDoc.DocumentElement; e.Prefix = "abc" When i simply write the document...
5
by: johanneskrueger | last post by:
Hello, I'm currently using <xsl:copy-of select="document(...)/svg:svg"/to embed an SVG file into an XHTML file. I already defined the SVG namespace and assigned svg as its prefix in my XSLT 1.0...
2
by: scottpet | last post by:
Hi, I want to add a namespace prefix to the root node of an object I am serializing to XML. I have been reading though this article:...
30
by: Xah Lee | last post by:
The Concepts and Confusions of Prefix, Infix, Postfix and Fully Functional Notations Xah Lee, 2006-03-15 In LISP languages, they use a notation like “(+ 1 2)” to mean “1+2”....
8
by: subramanian100in | last post by:
Consider int i = 10; Why do we say that ++i yields an Lvalue and i++ yields an Rvalue ? I thought both these expressions yield only values. I am unable to understand the difference
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
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,...
0
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...
0
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...
0
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...
0
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 projectplanning, coding, testing,...

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.