[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Newbie: template match using a mix of namespace pr

Subject: Re: Newbie: template match using a mix of namespace prefix and none p refix
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Mon, 9 Sep 2002 10:09:09 +0100
oagis_fields
Hi Magnus,

(Sorry, I read "Palmer Magnus" as meaning your first name was
Palmer...)

>> 1) Absolute path, not working
>> <xsl:template
>>
> match="/msg/req/dta/SHOW_PO_007/DATAAREA/SHOW_PO/POHEADER/of:USERAREA/of:TRA
>> NSMETHD" mode="copy">
>
> <<My guess would be that these paths aren't working because the msg,
> <<req, dta, SHOW_PO_007, DATAAREA, SHOW_PO and/or POHEADER elements are
> <<in a namespace in your XML document. Without seeing your source
> <<document I can't tell, but this seems to be the most likely
> <<explanation.
>
> The namespaces are as following:
> <xsl:stylesheet version="1.0" 
> xmlns="x-schema:http://scshost/schemas/oagis/7.1/011_show_po_007.xdr"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> xmlns:of="x-schema:http://scshost/schemas/oagis/7.1/oagis_fields.xdr" 
> xmlns:os="x-schema:http://scshost/schemas/oagis/7.1/oagis_segments.xdr" 
> xmlns:scala="x-schema:http://scshost/schemas/oagis/7.1/scala_fields.xdr"
>>
> Hence I asume that the default namespace is using the 011_show_po_007.xdr
> namespace.

Yes, that's the default namespace in the stylesheet. I assume that's
the default namespace in the XML document as well?

The thing is that XSLT (or rather XPath) doesn't use the default
namespace when interpreting element names in XPath. If you use the
path:

  SHOW_PO_007

then this always selects the SHOW_PO_007 element *in no namespace*, no
matter what the default namespace is at the point where you use that
path. Setting the default namespace in the stylesheet only influences
the namespace of the literal result elements that you create within
the stylesheet, it cannot be used when selecting nodes from the source
document.

You therefore have to give this default namespace a prefix, e.g.:

<xsl:stylesheet version="1.0"
  xmlns:po="x-schema:http://scshost/schemas/oagis/7.1/011_show_po_007.xdr"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:of="x-schema:http://scshost/schemas/oagis/7.1/oagis_fields.xdr"
  xmlns:os="x-schema:http://scshost/schemas/oagis/7.1/oagis_segments.xdr"
  xmlns:scala="x-schema:http://scshost/schemas/oagis/7.1/scala_fields.xdr">
...
</xsl:stylesheet>

Here I've assigned the prefix 'po' to stand in for the namespace
"x-schema:http://scshost/schemas/oagis/7.1/011_show_po_007.xdr". You
can now refer to the SHOW_PO_007 element *in the namespace
"x-schema:http://scshost/schemas/oagis/7.1/011_show_po_007.xdr"* with:

  po:SHOW_PO_007

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.