Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 22nd, 2011, 08:40 AM
Authorized User
 
Join Date: Nov 2007
Posts: 31
Thanks: 6
Thanked 0 Times in 0 Posts
Default Default Namespace - Avoid Using Prefix

Hi all,
I understand namespaces are a big topic in this forum and I have gone through a lot of the material on here, but have a bit of a more specific question.

My source xml is along the lines of:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<City xmlns="http://somenamespace.com">
  <Street>
    <House>my cottage</House>
.....
As you can see there is a default namespace.
In my xslt I have defined a prefix set to that namespace, and if I use this prefix in any xpath it works fine, e.g:
Code:
<xsl:stylesheet xmlns:xyz="http://somenamespace.com">
...
<xsl:value-of select="xyz:City/xyz:Street/xyz:House" />
...
The value-of is within a template that is called based on the match "*|/", i.e. everything.

Like I say, this works fine, but I have a large stylesheet and want to avoid using xyz: in front of every tag.

Is there a way to tell the stylesheet every tag is in this namespace? Basically so I can use a value-of such as "City/Street/House".

Removing even one of these xyz: prefixes currently returns nothing.

Thanks in advance,
__________________
Neil Belch
Technical Officer
CDL

The views opinions and judgements expressed in this message are solely those of the author. The message contents have not been reviewed or approved by CDL.
 
Old July 22nd, 2011, 08:50 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

With XSLT 2.0 and an XSLT 2.0 processor like Saxon 9 or Altova or XQSharp use xpath-default-namespace="http://somenamespace.com" on your xsl: stylesheet element.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old August 3rd, 2011, 08:09 AM
Authorized User
 
Join Date: Nov 2007
Posts: 31
Thanks: 6
Thanked 0 Times in 0 Posts
Default

Hi Martin, thanks for your response.

I haven't had a chance to revisit this work I'm doing, hence the delay in responding.

Our xslt processor is version 1.0 unfortunately, is there a way to do it on that version?
__________________
Neil Belch
Technical Officer
CDL

The views opinions and judgements expressed in this message are solely those of the author. The message contents have not been reviewed or approved by CDL.
 
Old August 3rd, 2011, 08:16 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

No, path-default-namespace is a new feature in XSLT 2.0. With XSLT 1.0 you need to use a prefix to qualify element names that belong to a namespace.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old August 3rd, 2011, 09:02 AM
Authorized User
 
Join Date: Nov 2007
Posts: 31
Thanks: 6
Thanked 0 Times in 0 Posts
Default

Thought that might be the case, looks like I have lots of namespace prefixes to add!

Thanks for your help Martin.
__________________
Neil Belch
Technical Officer
CDL

The views opinions and judgements expressed in this message are solely those of the author. The message contents have not been reviewed or approved by CDL.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Exclude a namespace with no prefix bonekrusher XSLT 6 January 23rd, 2009 08:48 AM
Remove namespace prefix from XmlBean ratzko BOOK: Professional Java Development with the Spring Framework 0 August 10th, 2008 01:23 PM
Adding Prefix and Namespace to XML Lerxt XSLT 6 November 8th, 2007 03:14 PM
How a additional prefix in a namespace comes? diang BOOK: ASP.NET Website Programming Problem-Design-Solution 0 July 13th, 2006 10:40 PM
attribute namespace prefix tsmith XSLT 1 August 12th, 2004 06:01 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.