xml - XSLT: Set namespace as first attribute -


I have a problem with the namespace status in xml file after xsl conversion.

My conversion stylesheet looks like

  & lt ;? XML version = "1.0" encoding = "ISO-885 9-1"? & Gt; & Lt; Xsl: stylesheet version = "1.0" xmlns: xsl = "http://www.w3.org/1999/XSL/Transform" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-Example" & Gt; & Lt; Xsl: output indent = "yes" method = "xml" /> & Lt; Xsl: template match = "/" & gt; & Lt; Xsl: element name = "SmartDriveUpdates" & gt; & Lt; Xsl: attribute name = "xsi: a namespace shadow location" & gt; & Lt; XSL: Text & gt; LightSpeedXMLSchema.xsd & lt; / XSL: text & gt; & Lt; / XSL: Specialty & gt; ... & lt; / Xsl: element & gt;   

In the output xml file, I want to root the node

  & lt; SmartDriveUpdates want to get the xmlns: xsi = "http: / /www.w3.org/2001/XMLSchema-instance" xsi: No Namsthansama location = "Laitsped XMLSchema.xsd" & gt;   

But instead I have

  & lt; SmartDriveUpdates xsi: noNamespaceSchemaLocation = "LightSpeedXMLSchema.xsd" xmlns: xsi = "http: //www.w3.org / 2001 / XMLSchema-Example" & gt;   

I also tried to prepond the root node in the xsl stylesheet

    

But I get the same wrong result.

Changed the XML file using the Transform method from System.xml.xsl.xslcompiledtransform.NET class. I use PowerShell to this objective:

  function Convert-WithXslt ($ originalXmlFilePath, $ xslFilePath, $ outputFilePath) {## dealing with simplified error $ xslFilePath = solution-path $ xslFilePath (-not (Test-path $ xslFilePath)) {throw "XSL file not found"} $ originalXmlFilePath = solution path throw $ originalXmlFilePath (-not (Test-path $ originalXmlFilePath)) { "did not XML file" if} # $ outputFilePath = solution-path $ outputFilePath (-not (Test-path (Split-path $ originalXmlFilePath))) {throw could not be found "output folder"} ## go to an XSL object conversion ( Shish new .Net version 3.5 before) $ EAP = $ ErrorActionPreference $ ErrorActionPreference = "SilentlyContinue" $ script: xslt = new-object system.xml.xsl.xslcompiledtransform trap [System.Management.Automation.PSArgumentException] {# No 3.5, using slower 2.0 $ Trutiakshnfyufrens = $ EAP $ script: xslt = new object Sistmkcl.akssel.aksseltronsform} $ Akshnakshnprfain = $ EAP ## load XSLT file $ xslt.load ($ XslFilePath) ## $ change xslt.Transform ($ OriginalXmlFilePath, $ outputFilePath)}   

Somebody solved this Switch to who can help?

Thanks

The sequence implementation of namespace definitions and attributes is dependent < / Strong>.

You have two options:

  1. Use another XSLT processor - Saxon 6.5.4 or Saxon 9.x (has a .NET version) Some versions of Altowa (XML-SPY) and XQSharp generate output as desired.

  2. Continue to use XslCompiledTransform, but apply your own XmlWriter object To make the serialization of the element desired, there is freedom in implementing the WriteElementString method ().

Comments