我正在尝试迭代 SVG 目录以访问其中的一些元数据。我可以很好地迭代,但是,当我尝试获取每个节点中特定节点的值时,我似乎失败了。
使用SaxonHE 9.4 (Java)进行转换。
这里的例子看起来很简单:
<xsl:value-of select="document('geneva.xml')/ph:photo/ph:title"/>
http://www.ibm.com/developerworks/xml/library/x-tipcombxslt/
但是我有我的 XSLT(相关部分;没有迭代 atm 只是获取外部节点值的测试):
<div>
<p><xsl:value-of select="document('images/test.svg')"/></p>
</div>
但这给我的是:
<div><p>Mine
circle:hover {fill-opacity:0.9;}
</p></div>
我尝试过 document('images/test.svg')/svg/title
但这没有给我任何返回
test.svg
<?xml version="1.0"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN"
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg xmlns="http://www.w3.org/2000/svg">
<title>Mine</title>
<style type="text/css">
circle:hover {fill-opacity:0.9;}
</style>
<g style="fill-opacity:0.7;">
<circle cx="6.5cm" cy="2cm" r="100" style="fill:red; stroke:black; stroke-width:0.1cm" transform="translate(0,50)" />
<circle cx="6.5cm" cy="2cm" r="100" style="fill:blue; stroke:black; stroke-width:0.1cm" transform="translate(70,150)" />
<circle cx="6.5cm" cy="2cm" r="100" style="fill:green; stroke:black; stroke-width:0.1cm" transform="translate(-70,150)"/>
</g>
</svg>
最佳答案
SVG 元素绑定(bind)到 SVG 命名空间。它的设置没有命名空间前缀:
<svg xmlns="http://www.w3.org/2000/svg">
因此,您需要在 XSLT 中使用 namespace 前缀声明该 namespace ,并使用该 namespace 前缀来寻址 XPath 中的 SVG 元素:
document('images/test.svg')/svg:svg/svg:title
关于xslt - 使用 document() XSLT 从外部 XML 访问节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12547804/