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 15th, 2009, 06:37 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

XSLT 1.0 doesn't give you a guaranteed way to get a particular prefix in the output but most processors will retain the prefix you use in the name attribute if possible, e.g.

<xsl:element name="icns:{local-name()}" namespace="{.....}">
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old January 15th, 2009, 06:51 AM
Authorized User
 
Join Date: Jan 2009
Posts: 36
Thanks: 3
Thanked 0 Times in 0 Posts
Default

This still does not work is there a way in xslt 2.0 to acheive the expected results ?
 
Old January 15th, 2009, 06:59 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Please don't say "it doesn't work" -that's useless information. Tell us exactly what you did and exactly how it failed, and then we can tell you what you did wrong.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old January 15th, 2009, 07:09 AM
Authorized User
 
Join Date: Jan 2009
Posts: 36
Thanks: 3
Thanked 0 Times in 0 Posts
Default

When i use
<xsl:element name="icns:{local-name()}" namespace="urn:Test">

the resulting xml is prefixed with icns in every node.
<icns:Print_Data xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:icns="urn:Test"
<icns:....></icns:....>
</icns:Print_Data>

i'm using built in Altova XML spy xsl parser
 
Old January 15th, 2009, 07:32 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

>When i use
> <xsl:element name="icns:{local-name()}" namespace="urn:Test">

>the resulting xml is prefixed with icns in every node.

So it does work - when you said it doesn't work, you were misleading us.

If you only want some nodes to use this prefix, then only use this construct on those nodes.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old January 15th, 2009, 08:17 AM
Authorized User
 
Join Date: Jan 2009
Posts: 36
Thanks: 3
Thanked 0 Times in 0 Posts
Default

Sorry for not being very clear.

Here's my input xml
<Print_Data xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:soapenc
="http://schemas.xmlsoap.org/soap/encoding/"xmlns:icns="urn:NewBusiness_ATV"</Print_Data>

here's the xsl i'm using
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi
="http://www.w3.org/2001/XMLSchema-instance"
xmlns:soapenv
="http://schemas.xmlsoap.org/soap/envelope/"xmlns:icns="urn:NewBusiness_ATV">

<xsl:template match="/">
<soapenv:Envelope>
<soapenv:Header>
<icns:IplusHeader>
<icns:freeFormatText>
Sample Text
</icns:freeFormatText>
</icns:IplusHeader>
</soapenv:Header>
</soapenv:Envelope>
</xsl:template>

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

<xsl:template match="*">
<xsl:element name="{name()}" namespace="urn:TEST">
<xsl:copy-of select="document('')/xsl:stylesheet/namespace::*[local-name() = 'icns']"/>
<xsl:copy-of select="namespace::*[not(local-name() = 'icns')]"/>
<xsl:apply-templates select="@* | node()"/>
</xsl:element>
</xsl:template>

I'm expecting the following result xml
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd
="http://www.w3.org/2001/XMLSchema"
xmlns:xsi
="http://www.w3.org/2001/XMLSchema-instance">
<
soapenv:Header>
<
icns:IplusHeader xmlns:icns="urn:TEST">
<
icns:freeFormatText>
Sample Text
</icns:freeFormatText>
</
icns:IplusHeader>
</
soapenv:Header>
</
soapenv:Envelope>

Last edited by nguna; January 15th, 2009 at 08:22 AM..
 
Old January 15th, 2009, 08:18 AM
jminatel's Avatar
Wrox Staff
Points: 18,059, Level: 58
Points: 18,059, Level: 58 Points: 18,059, Level: 58 Points: 18,059, Level: 58
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2003
Posts: 1,906
Thanks: 62
Thanked 139 Times in 101 Posts
Default

FYI, you were just getting caught by the spam filter. It's still fine tuning. ;) Your reply is visible now.
__________________
Jim Minatel
Associate Publisher, WROX - A Wiley Brand
Did someone here help you? Click on their post!





Similar Threads
Thread Thread Starter Forum Replies Last Post
What is ".Namespace" ?! Employee C# 2 May 14th, 2008 10:55 AM
namespace Tomi XML 0 September 14th, 2007 04:39 AM
Namespace help CamosunStudent BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 1 October 6th, 2006 04:12 PM
change namespace leaving prefix unchanged lantoli XSLT 3 June 26th, 2006 07:31 AM
How can I change the default namespace allanhu BOOK: ASP.NET Website Programming Problem-Design-Solution 1 November 1st, 2004 01:15 PM





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