remove xmlns attribute from namespace prefix node
I'm trying to use XSLT to create Edge Side Includes html blocks.
Here is a sample XSLT
<xsl:stylesheet version="1.0"
xmlns:xsl开发者_StackOverflow中文版="http://www.w3.org/1999/XSL/Transform"
xmlns:esi="http://www.edge-delivery.org/esi/1.0"
exclude-result-prefixes="xsl esi">
<xsl:output method="html"
media-type="text/html"
version="1.0"
encoding="UTF-8"
indent="no"
omit-xml-declaration="yes"/>
<xsl:template match="/">
<esi:vars>
<xsl:text>some text goes here</xsl:text>
</esi:vars>
</xsl:template>
</xsl:stylesheet>
While the transformation works per-se, the output is this:
<esi:vars xmlns:esi="http://www.edge-delivery.org/esi/1.0">some text goes here</esi:vars>
problem is, the xmlns:esi attribute horribly breaks ESI execution. If I remove the attribute manually (eg: open the HTML and delete it, saving the code block again) everything works fine.
Question: How can I remove the xmlns:esi from the HTML output? I tried including it in exclude-results-prefixes, but didn't work.
Sample output that WILL work:
<esi:vars>some text goes here</esi:vars>
Question: How can I remove the xmlns:esi from the HTML output? I tried including it in exclude-results-prefixes, but didn't work.
XSLT with output method xml cannot produce non-well-formed XML.
When the namespace declaration is deleted manually, the "esi:"
prefix becomes not bound to any namespace and thie whole document thus becomes non-well-formed.
According to the ESI Spec., the esi namespace must typically be declared in the top element (<html>
) of the document.
Try this:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:esi="http://www.edge-delivery.org/esi/1.0">
<xsl:output indent="no" omit-xml-declaration="yes"/>
<xsl:template match="/">
<html xmlns:esi="http://www.edge-delivery.org/esi/1.0">
<esi:vars>
<xsl:text>some text goes here</xsl:text>
</esi:vars>
</html>
</xsl:template>
</xsl:stylesheet>
which produces:
<html xmlns:esi="http://www.edge-delivery.org/esi/1.0">
<esi:vars>some text goes here</esi:vars>
</html>
With any input, this stylesheet:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:text><esi:vars></xsl:text>
<xsl:text>some text goes here</xsl:text>
<xsl:text></esi:vars></xsl:text>
</xsl:template>
</xsl:stylesheet>
Result:
<esi:vars>some text goes here</esi:vars>
Note: For no-well-formed output you can use DOE or TEXT serialization only.
I've found the professional way to do it. The right answer depends on the following:
<xsl:stylesheet
version="1.0" xmlns:asp="remove"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:app="http://myNamespace.com/app"
exclude-result-prefixes="app">
use this function here exclude prefixes
exclude-result-prefixes
For more information: http://msdn.microsoft.com/en-us/library/ms256204.aspx
精彩评论