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 January 13th, 2009, 03:34 PM
Authorized User
 
Join Date: Apr 2008
Posts: 70
Thanks: 17
Thanked 1 Time in 1 Post
Send a message via Yahoo to iceandrews
Default Namespace Output

I have a complicated question. I apologize if I don't articulate it enough on the first pass; I'm in the process of learning namespaces/schema/xslt in depth.

So, the basic idea of my question is this: Is there a method/way to produce something that has the opposite effect of the "exclude-result-prefixes=" " " instruction.

I have an incoming document that is in no namespace. I have a schema that has a
elementFormDefault="qualified". So we need to be able to produce a document with the prefixes of a certain namespace.

Is there a method within the XSLT or during output, where using the schema, to convert the default namespace that has no prefix into a defined namespace (both in the schema and the would-be resulting document) where all the elements have the explicit namespace prefix?

We would like to be able to do this without having to process each node state that it should have the prefix in front of the element. So in other words, some kind of switch that says....all the output document’s element has namespace prefixes or not.

If you need some small examples that may better spell it out let me know and I can work something up. At the moment, our examples contain lots of private data.

Thank you ahead of time.
 
Old January 14th, 2009, 12:14 PM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

It is not clear what you want to achieve. First you say you have an "incoming document in no namespace", later you say you want to "convert the default namespace that has no prefix into a defined namespace".
If you have elements in no namespace and want to transform them into elements in a certain namespace then here is an example:
Assume the XML input is
Code:
<root>
  <foo att1="value 1">
    <bar>foobar</bar>
  </foo>
</root>
Then this stylesheet
Code:
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0">
  
  <xsl:param name="ns" select="'http://example.com/2009/ns1'"/>
  <xsl:param name="pf" select="'foo'"/>
  
  <xsl:template match="*">
    <xsl:element name="{concat($pf, ':', local-name())}"
                 namespace="{$ns}">
      <xsl:apply-templates select="@* | node()"/>
    </xsl:element>
  </xsl:template>
  
  <xsl:template match="@* | comment() | text() | processing-instruction()">
    <xsl:copy/>
  </xsl:template>

</xsl:stylesheet>
creates the following result:
Code:
<?xml version="1.0" encoding="utf-8"?><foo:root xmlns:foo="http://example.com/2009/ns1">
  <foo:foo att1="value 1">
    <foo:bar>foobar</foo:bar>
  </foo:foo>
</foo:root>
So it transforms all elements to elements with namespace and prefix given as the parameters ns and pf.

Is that what you want to achieve?
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog





Similar Threads
Thread Thread Starter Forum Replies Last Post
Remove namespace from output file jopet25 XSLT 12 March 9th, 2007 11:12 AM
Two namespace contain same name nir_pankaj C# 1 February 21st, 2007 12:30 PM
Namespace ~Bean~ Classic ASP Basics 2 June 3rd, 2005 02:31 PM
namespace Ibn_Aziz C# 2 December 25th, 2003 05:41 AM
namespace within namespace Bill Crawley XML 1 December 11th, 2003 10:59 AM





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