 |
| 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 19th, 2010, 04:11 AM
|
|
Authorized User
|
|
Join Date: Oct 2010
Posts: 25
Thanks: 8
Thanked 0 Times in 0 Posts
|
|
defining namespaces for source and target
Hello,
I have written a xslt file that transforms a xml file based on a older schema to the newer schema, well sort of. everything was working correctly until I realized that in the xslt file I was using the older schema in the <xsl:stylesheet> node. This namespce with other namespaces were copied to my target xml file, which was incorrect, so I changed it to the new schema and now nothing is working?? I don't get the nodes just the value of nodes. I don't understand why is this happening. I thought that when I write a xslt, the parser will read and match the nodes in the source file with the templates I have created and based on the template create an output in the target file, so why does this happen the source file hasn'e changed and neither the templates? is there any way to fix this by saying that the source is based on this schema and the target is based on the other schema?
regards,
es
|
|

October 19th, 2010, 04:37 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
Usually when converting from one namespace to another you will see both namespaces defined in the xsl:stylesheet element.
But without seeing some of your actual code I don't really want to comment further.
|
|

October 19th, 2010, 04:44 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
Changing the namespace in the root element of your document seems like a very small change, but you need to realise that it changes everything. As far as the stylesheet is concerned, it's like changing all the element names from upper case to lower case - nothing will match any more. If the stylesheet is designed to work on names in a particular namespace, then it won't work on names in a different namespace.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
|
|
The Following User Says Thank You to mhkay For This Useful Post:
|
|
|

October 19th, 2010, 05:11 AM
|
|
Authorized User
|
|
Join Date: Oct 2010
Posts: 25
Thanks: 8
Thanked 0 Times in 0 Posts
|
|
thanks for both comments,
I've just realized I the two schemas are using the same namespace id,
so when I changed it to the new one, it was infact trying to read the source based on the new one. Now my question is since I'm not allowed to change the schemas is there any way to say that in the target file use this url and not the otherone.
ehsan
|
|

October 19th, 2010, 05:15 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
No, that's not how it works unfortunately. You'd need to define two namespaces, and select everything in your input XML using one, and output everything using the other. E.g:
Code:
<xsl:stylesheet xmlns:old="http://old.com" xmlns:new="http://new.com" ...>
<xsl:template match="old:element">
<new:element>...</new:element>
</xsl:template>
...
If you provided us with examples of your code and xml we could probably help you much better.
|
|
The Following User Says Thank You to samjudson For This Useful Post:
|
|
|

October 19th, 2010, 06:59 AM
|
|
Authorized User
|
|
Join Date: Oct 2010
Posts: 25
Thanks: 8
Thanked 0 Times in 0 Posts
|
|
out of curiosity, based on the discussion above if I do something like this
Code:
<xsl:element name="benew:forretningsadress">
<xsl:copy-of select="be:adresse"/>
<xsl:element name="benew:kommunennummer"/>
</xsl:element>
is it possible using xslt to change the prefix "be" in be:adresse to "benew" after the <xsl:copy-of> ?
ehsan
|
|

October 19th, 2010, 07:20 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
No. xsl:copy-of copies an xml element - an xml element is defined by its fully qualified name (i.e. the local name and the namespace), so changing the namespace it becomes a completely different element - hence 'copy' can't be used.
|
|
 |