Prefix problem with XML/XSL

J

Jacques

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:eek:utput 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
 
P

Philippe Poulard

Jacques said:
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>

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:eek:utput 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 |
-----------------------
 
R

Rolf Magnus

Jacques said:
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:eek:utput 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.
 
J

Jacques

Thank you for a very informative explanation, as well as a practical
solution.
It works now, and I understand why.

Regards
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top