xsl-list
[Top] [All Lists]

RE: [xsl] Xpath errors in XML to XML transformation

2009-06-22 05:23:50

Learning by example can work very well for some people, but there's always a
danger that you miss some of the concepts - or even worse, that you build an
incorrect mental model of why the examples work. It's a good idea to
supplement it with some reading about the concepts in the language.

In this case, you don't seem to have grasped the correct model for
namespaces. Element names are "QNames", consisting of a namespace URI and a
local name; the prefix is a local shortcut for an URI. For an XPath step to
match an element name, the namespace URIs and local names have to match; the
prefixes are irrelevant. The name of your root element has namespace URI
http://docbook.org/docbook-ng, local name chapter, and it will only match a
corresponding step in a path expression.

If you're using XSLT 1.0, declare a prefix for this namespace in your
xsl:stylesheet element

xmlns:db="http://docbook.org/docbook-ng";

and then select the element as db:chapter.

If you're using XSLT 2.0 another option is to declare the namespace for
unprefixed names in path expressions:

xpath-default-namespace="http://docbook.org/docbook-ng";

Regards,

Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay   

-----Original Message-----
From: Catherine Pouncett 
[mailto:C(_dot_)Pouncett(_at_)autodata(_dot_)ltd(_dot_)uk] 
Sent: 22 June 2009 10:09
To: XSL Wrox forum (E-mail)
Subject: [xsl] Xpath errors in XML to XML transformation


      Hi,

      This is my first post on this forum, I'm just beginning 
to learn XSL. Working with simple examples is going great. I 
have now come across a problem and do not know how to sort it 
out and I wondered if someone could point me in the right direction?

      I have managed to transform XML to XML etc using simple 
examples. Then I took some of my work files, things weren't 
working, when checking my Xpath, the results were coming up 
false etc. We have lots of info in the top tag 'chapter', if 
I remove everything apart from the namespace ad declaration 
the file transforms correctly. So, does this have something 
to do with the Schema? or, docbook?
      Any help on this would be much appreciated as I don't 
know where to start looking.


      Xpath works perfectly with the below root tag in my XML files:-

      <chapter xmlns:ad="http://myhome/technical_topic";>



      Xpath does not work with the below root tag in my XML files:-

      <chapter  xmlns="http://docbook.org/docbook-ng"; 
xmlns:ad="http://myhome/technical_topic";
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
          xsi:schemaLocation="http://docbook.org/docbook-ng 
//myserver/myfolder/XmlSchemaStylesheet/docbook.xsd"
          version="IPA-ext-Caffs-0.5" xml:lang="en">

      Hope this makes sense.

      Kind Regards,
      Catherine

Catherine Pouncett
tel: +44 1628 688182
c(_dot_)pouncett(_at_)autodata(_dot_)ltd(_dot_)uk 


IMPORTANT NOTICE: This email and any attachments are 
confidential and are protected by copyright and/or database 
rights and are intended for the addressee only. If you are 
not the named recipient, you must not use, disclose, 
reproduce, copy or distribute the contents of this 
communication. If you have received this in error, please 
contact the sender and then delete this email from your 
system. The integrity of email across the Internet cannot be 
guaranteed. The sender therefore does not accept liability 
for any errors or omissions in the contents of this message 
which arise as a result of email transmission. Although 
Autodata Limited has taken precautions to ensure no viruses 
are present in this email or any attachments, the company 
cannot accept any responsibility for any loss or damage 
arising from the use of this email or attachments. Autodata 
Limited, Priors Way, Maidenhead Berkshire, SL6 2HP, England, 
UK. Registered as a limited company in England, UK. 
Registration number 1062717. VAT number GB 208 4782 54.

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>