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

Re: Target Namespace in XML breaks XSL transform

Subject: Re: Target Namespace in XML breaks XSL transform
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Fri, 24 Mar 2006 14:06:20 -0500
xsl target namespace
At 2006-03-24 10:51 -0800, Allison Bloodworth wrote:
When I specify a target namespace for the root element in my XSL document,

e.g. <Events xmlns="urn:cde.berkeley.edu:babl:events:1.00"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:cde.berkeley.edu:babl:events:1.00 UCBEvents.xsd">

it appears that I then need to use a namespace prefix for every element from
that document referenced in my XSL transform.

Correct ... that is conformant behaviour for XSLT 1.


By adding a default namespace at the document element you have just changed every unprefixed element in the document.

So I can't do this:
<xsl:value-of select="Events/View/FormatCalendar/ShortName"/>

Yes, you cannot, since those are not elements in your namespace.


But instead have to do this:
<xsl:value-of select="ev:Events/ev:View/ev:FormatCalendar/ev:ShortName"/>

Right again. By specification, XPath 1 does not use the default namespace.


This is a huge stylesheet and there are three different stylesheets I'd have
to modify, so to do this MANY changes will have to be made.

Well, you have just made MANY changes to your XML.


I need the
target namespace in my XML document if I want to validate it. Is there any
way around modifying all my XSLs?

You could write a pre-processing stylesheet that strips all namespaces from the input and then apply the resulting instance with elements in no namespace against your existing stylesheets. That way you run your raw instances for validation and your processed instances for formatting.


A modification of the identity stylesheet would do ... I hope the code below helps.

. . . . . . . . . . Ken

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="1.0">

<xsl:template match="text()|comment()|processing-instruction()">
  <xsl:copy/>
</xsl:template>

<xsl:template match="*">
  <xsl:element name="{local-name(.)}">
    <xsl:apply-templates select="@*|node()"/>
  </xsl:element>
</xsl:template>

<xsl:template match="@*">
  <xsl:attribute name="{local-name(.)}">
    <xsl:value-of select="."/>
  </xsl:attribute>
</xsl:template>

</xsl:stylesheet>


-- Upcoming XSLT/XSL-FO hands-on courses: Washington,DC 2006-06-12/16 World-wide on-site corporate, govt. & user group XML/XSL training. G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (F:-0995) Male Cancer Awareness Aug'05 http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal

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.