 |
| 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
|
|
|
|

October 28th, 2011, 06:24 AM
|
|
Authorized User
|
|
Join Date: Oct 2011
Posts: 30
Thanks: 2
Thanked 0 Times in 0 Posts
|
|
help please on namespaces
When i have the following xslt :
***************************
<xsl:stylesheet
xmlns:glml="http://www.globallink.com/schemas/fxcng/glml/v67/extra"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:com="http://www.globallink.com/schemas/fxcng/glml/v67/common"
xmlns:mar="http://www.globallink.com/schemas/fxcng/glml/v67/market"
xmlns="http://http://www.w3.org/TR/REC-html40"
xmlns:SOAP="net.sf.kernow.soapextension.SOAPExtens ion"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope"
version="1.0"
exclude-result-prefixes="xs">
<xsl:output method="xml" encoding="utf-8" indent="yes"/> <!-- Can remove this later on when sending the files over tibco but keep it in now for developmental reasons to see the file correctly-->
<xsl:template match = "/">
<xsl:element name="SOAP-ENV:Envelope">
<xsl:attribute name ="xmlns:SOAP-ENV">
<xsl:value-of select= "http://www.w3.org/2003/05/soap-envelope"/>
</xsl:attribute>
*********************
I get the following error message
C:\work\XSLT\test.xsl (23,9): error: Prefix 'xmlns' is not defined.
C:\work\XSLT\test.xsl (24,11): error: Expected end of the expression, found ':'.
http -->:<-- //www.w3.org/2003/05/soap-envelo...
please advise
thx
|
|

October 28th, 2011, 06:31 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
Use the xsl:element namespace attribute to assign a namespace to an element.
http://www.w3schools.com/xsl/el_element.asp
|
|

October 28th, 2011, 06:36 AM
|
|
Authorized User
|
|
Join Date: Oct 2011
Posts: 30
Thanks: 2
Thanked 0 Times in 0 Posts
|
|
thanks for responser.. please an you clarify
element name = SOAP-ENV:Envelope
namespace = xmlns:SOAP-ENV
value = www..ws.......
how does this work?
|
|

October 28th, 2011, 06:40 AM
|
|
Authorized User
|
|
Join Date: Oct 2011
Posts: 30
Thanks: 2
Thanked 0 Times in 0 Posts
|
|
This is what i want
SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope">
<! some stuff -->
</SOAP-ENV:Envelope>
|
|

October 28th, 2011, 06:45 AM
|
|
Authorized User
|
|
Join Date: Oct 2011
Posts: 30
Thanks: 2
Thanked 0 Times in 0 Posts
|
|
no matter.. think i have cracked it.. thanks
|
|

October 28th, 2011, 06:49 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
Namespaces in the XSLT data model are not attributes, and they are not created using xsl:attribute.
You seem to know the name of the element you want to create statically, so just use a literal result element. Replace this:
Code:
<xsl:element name="SOAP-ENV:Envelope">
<xsl:attribute name ="xmlns:SOAP-ENV">
<xsl:value-of select= "http://www.w3.org/2003/05/soap-envelope"/>
</xsl:attribute>
...
</xsl:element>
with this:
Code:
<SOAP-ENV:Envelope xmlns="http://www.w3.org/2003/05/soap-envelope">
...
</SOAP-ENV:Envelope>
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
|
|

October 28th, 2011, 06:59 AM
|
|
Authorized User
|
|
Join Date: Oct 2011
Posts: 30
Thanks: 2
Thanked 0 Times in 0 Posts
|
|
along the same theme...
how do i get the following output in xml from the transform
<ns:FXTradeVersion xmlns:xs="http://www.w3.org/2001/XMLSchema" ns0:mustUnderstand="1" xsi:type="xs:string" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns0="http://www.w3.org/2003/05/soap-envelope" xmlns:ns="http://schemas.westpac.com.au/wib/icc/fx/service/tradenotification-1-0">1.0</ns:FXTradeVersion>
thank you
|
|

October 28th, 2011, 07:03 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
Just type it as you see it. Unless something in that XML relies on your input you can just type it straight it into the XSLT document.
If something does depend on your input XML then you would have to show us your input XML and how the output will depend on it.
|
|

October 28th, 2011, 07:07 AM
|
|
Authorized User
|
|
Join Date: Oct 2011
Posts: 30
Thanks: 2
Thanked 0 Times in 0 Posts
|
|
<xsl:element name ="ns:FXTradeVersion xmlns:xs="http://www.w3.org/2001/XMLSchema" ns0:mustUnderstand="1" xsi:type="xs:string" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns0="http://www.w3.org/2003/05/soap-envelope" xmlns:ns="http://schemas.westpac.com.au/wib/icc/fx/service/tradenotification-1-0" ">
like you suggested gives the following error
XmlException
------------
'http' is an unexpected token. Expecting white space. Line 29, position 59.
|
|

October 28th, 2011, 07:12 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
Forget xsl:element!
If you know the name of the element you want to create you just write it like you want to output it.
Code:
<xsl:template match = "/">
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope">
<ns:FXTradeVersion xmlns:xs="http://www.w3.org/2001/XMLSchema" ns0:mustUnderstand="1" xsi:type="xs:string" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns0="http://www.w3.org/2003/05/soap-envelope" xmlns:ns="http://schemas.westpac.com.au/wib/icc/fx/service/tradenotification-1-0">1.0</ns:FXTradeVersion>
</SOAP-ENV:Envelope>
</xsl:template>
This does kind of defeat the purpose of using XSLT, as doing anything other than outputting a static XML file, but it is certainly feasible.
|
Similar Threads
|
| Thread |
Thread Starter |
Forum |
Replies |
Last Post |
| Namespaces |
lustigon |
BOOK: Beginning ASP.NET 4 : in C# and VB |
1 |
October 4th, 2010 02:40 AM |
| Dynamic namespaces |
Clemensl |
XSLT |
7 |
June 17th, 2010 12:01 PM |
| Namespaces |
Amateur |
BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 |
1 |
November 27th, 2006 05:19 PM |
| namespaces |
anchal |
C# |
1 |
July 3rd, 2006 02:53 PM |
| NAMESPACES - WHAT ARE THEY? |
p_nut33 |
C# |
2 |
July 31st, 2003 03:18 AM |
|
 |