質問

So In one of my xslt files, I see

<xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:myxsl="urn:schemas-microsoft-com:xslt"
    xmlns:xsl2="http://www.w3.org/TR/xslt20/" 
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:java="http://xml.apache.org/xalan/java" 
    xmlns:mine="com.my.example.impl.BaseImpl"
    xmlns:m="com.my.example.util.CustomXsltHashMap"  
    xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"
    exclude-result-prefixes="myxsl java s mine m xs xsl2">

Can someone tell me what each line here means? I will really appreciate a line by line interpretation of these namespaces and their uses?

I am using xslt transformation from within the Java services somehow. (not my code).

Thanks

役に立ちましたか?

解決

Just to clear this up: I think I have told you already that namespaces have no meaning by themselves.

So, you should already know that

xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

is the namespace associated with XSLT transformations. In this case, anything prefixed with xsl is interpreted as an instruction to the XSLT processor.


Analogously,

xmlns:myxsl="urn:schemas-microsoft-com:xslt"

allows elements to be associated with MSXSL scripting, as described here.


The next namespace looks similar to the first one, don't you think?

xmlns:xsl2="http://www.w3.org/TR/xslt20/"

Elements prefixed with xsl2 might be exclusive to XSLT 2.0, as the link refers to the specification of XLST 2.0.


The next one is concerned with the use of an XML Schema:

xmlns:xs="http://www.w3.org/2001/XMLSchema"

XML documents can be validated against a schema, which is essentially a description of what it should contain and how the content should be organized.


You should be able to sort out the rest yourself, I think. How about googling the namespace URIs?

他のヒント

http://www.w3.org/1999/XSL/Transform is the namespace of the W3C XSLT programming language so it is the namespace of all instructions in the XSLT code.

http://www.w3.org/2001/XMLSchema is the namespace of the W3C XML schema language, it is common to use it in XSLT 2.0 stylesheet as the type system of XSLT/XPath 2.0 and later builds on the schema language; in an XSLT 1.0 stylesheet is is unusual to use that namespace but you have not shown much of the code so it is hard to tell why the stylesheet declares it.

urn:schemas-microsoft-com:xslt is the namespace Microsoft uses to provide proprietary extension functions and elements with its XSLT 1.0 processor implementations. http://www.w3.org/TR/xslt20/ is the location of the XSLT 2.0 specification, but I don't think it is used as a namespace normally.

Xalan is an XSLT 1.0 processor from the Apache software foundation but its documentation http://xml.apache.org/xalan-j/extensions.html says the namespace for extensions is http://xml.apache.org/xalan and not the one http://xml.apache.org/xalan/java used in your code so I can't tell why that snippet has http://xml.apache.org/xalan/java.

SOAP is also a W3C specification, it has various versions, I think the namespace http://schemas.xmlsoap.org/soap/envelope/ is for the SOAP 1.1 envelope part. The stylesheet might need to process SOAP messages and therefore needs to have that namespace declared to select or match input elements in that namespace.

The other two namespaces might be used to access extension objects, that is very processor specific.

exclude-result-prefixes="myxsl java s mine m xs xsl2"

This line tells to not include a namespace declaration for each of the given namespaces in the XML output. Without it, you would have a lot of xmlns:xxx="..." declarations in the output.

I suspect it's a Xalan stylesheet that makes heavy use of the Xalan calling convention for external Java methods. Since this calling convention maps XML namespaces to Java classes, it can cause a proliferation of namespaces.

You can google for the namespace (use "http://www.w3.org/1999/XSL/Transform", i.e. keep the quotes to Google knows you're looking for the whole thing). That should give you some useful results.

The reason why you see so many namespaces here is that XSLT made the mistake to use XML as the file format to define the transformations. XML has no scope (like Java or other real programming languages). Instead, they use namespaces to say "this name element means ...".

So if you produce XML and you want <output> in the result, you need a way to tell your XSLT tool that this isn't the same as <xsl:output>.

This leaks into everything which in turn yields such long lists of namespaces, especially when you run into one of the many shortcomings of XSLT (like it would take 5 lines of Java or 500 lines of XSLT -> write a Java plugin).

That also means it's not clear from the namespace declaration alone what it means. It might trigger a plugin, it might be necessary to add XML output to the stylesheet or it might be a leftover from cut&waste by someone who had no clue what all these odd strings mean.

Good luck.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top