我有一个这样的文件:
<?xml-stylesheet type="text/css" href="http://ltw1001.web.cs.unibo.it/svg.css" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:svg= "http://www.w3.org/2000/svg">
<body>
<svg:svg width="500" height="560" version="1.1" >
...
...
</svg:svg></body></html>
我应该只提取我尝试过的正文内容:
<?xml version="1.0" standalone="no"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/HTML/1998/html4">
<xsl:template match="/">
<xsl:value-of select="//body" />
</xsl:template>
</xsl:stylesheet>
但它不起作用
最佳答案
您(至少)有两个问题:
如果您想要完成的只是将 SVG 部分输出为 SVG 文档类型,请执行以下操作:
<xsl:output ...>
标签 doctype-public
和 doctype-system
指定要输出的文档类型信息的属性。 这是未经测试的,但应该非常接近。您必须添加文档类型信息:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns="http://www.w3.org/1999/xhtml"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:svg= "http://www.w3.org/2000/svg"
version="2.0">
<xsl:output method="xml" doctype-public="..." doctype-system="..."/>
<xsl:template match="/">
<xsl:apply-templates select="//svg:svg"/>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
关于xml - xslt 问题(命名空间?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3151472/