kam Posted July 4, 2007 Share Posted July 4, 2007 Hi,I am using XSLT to transform one xml to another xml.It works fine for source XML without namespaces in its root tag.But for an XML with namespaces like this, the XSLT doesnt work.<MappingDefinitions xmlns="urn:al:up-mapping:2005-05" xmlns:dt="urn:al:dst-v2" xmlns:rules="urn:al:dst-v2" xmlns:tps="urn:al:upp-services-types:2005-05" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:al:up-mapping:2005-05 ..\..\..\Generic\MappingDefinition\UP-Profile-Mapping-v50.xsd">Can anyone help me out Link to comment Share on other sites More sharing options...
boen_robot Posted July 4, 2007 Share Posted July 4, 2007 That's because XPath is namespace aware even when you might think it's not.You need to specify the namespace in the XSLT file itself if you want to get it working, like so: <xsl:stylesheet xmlns:p="urn:al:up-mapping:2005-05" xmns...> and when you need to match a certain element in that XSLT, you'd use that prefix before it's name, like so: p:MappingDefinitions of course, the prefix can be anything you want, as long as it refers to the same URI. Note that it's only in that XSLT where this applies. The XML can remain without prefix, as long as it has a default namespace pointing to the same URI (the way which is in your example).If you want, you could select an element regarless of it's namespace like so: *[local-name() = MappingDefinitions] Link to comment Share on other sites More sharing options...
kam Posted July 4, 2007 Author Share Posted July 4, 2007 That's because XPath is namespace aware even when you might think it's not.You need to specify the namespace in the XSLT file itself if you want to get it working, like so:<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:p="urn:alcatel:up-mapping:2005-05" xmlns:dt="urn:al:dst-v2" xmlns:rules="urn:al:dst-v2" xmlns:tps="urn:al:up-services-types:2005-05" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:al:up-mapping:2005-05 ..\..\..\Generic\MappingDefinition\UP-Profile-Mapping-v50.xsd"> Link to comment Share on other sites More sharing options...
boen_robot Posted July 4, 2007 Share Posted July 4, 2007 Errr... it's not valid according to what? Does the stylesheet work at all?If it does, but it doesn't validate according to the attached schema, it might be like that if the schema is suppose to validate the output rather then the input, and it is XSLT intput you're trying to validate.If you want to validate the output instead of the input, XSLT 2.0 allows you to do that by adding <xsl:import-schema namespace="..." schema-location="..."/> but filling the attributes properly of course. Note also that this requires a schema aware processor. For your example, you could do that like so: <xsl:import-schema namespace="urn:al:up-mapping:2005-05" schema-location="..\..\..\Generic\MappingDefinition\UP-Profile-Mapping-v50.xsd"/> and remove the xsi attributes. Link to comment Share on other sites More sharing options...
kam Posted July 5, 2007 Author Share Posted July 5, 2007 Errr... it's not valid according to what? Does the stylesheet work at all?If it does, but it doesn't validate according to the attached schema, it might be like that if the schema is suppose to validate the output rather then the input, and it is XSLT intput you're trying to validate.If you want to validate the output instead of the input, XSLT 2.0 allows you to do that by addingThe File is not Valid.The element Declaration was not found for root element 'xsl:stylesheet' Because of this I am not able to do XSL transformation from Authentic..........So I want to know, whether any changes must be done to the namespaces in StyleSheet node Link to comment Share on other sites More sharing options...
boen_robot Posted July 5, 2007 Share Posted July 5, 2007 As I said, remove the xsi attributes. The whole xsi namespace. It's causing validation of the XSLT file by using a schema that's not meant for it.XSLT 2.0 allows you to insert those namespaces only in the output by the means of xsl:namespace or xsl:namespace-alias. Link to comment Share on other sites More sharing options...
kam Posted July 5, 2007 Author Share Posted July 5, 2007 As I said, remove the xsi attributes. The whole xsi namespace. It's causing validation of the XSLT file by using a schema that's not meant for it.XSLT 2.0 allows you to insert those namespaces only in the output by the means of xsl:namespace or xsl:namespace-alias.Ya... It is working fine Thanks a Lot Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.