我试图弄清楚这段代码有什么问题,但是,4小时后,我放弃了!我在 stackoverflow 上尝试了很多不同的解决方案,并且从 arround 网络上尝试了很多不同的解决方案,但它们都不起作用。
我要做的就是将“gml:coordinates”值放入“point”属性。我想这与命名空间有关。或者是其他东西...
XML 文件:
<?xml version="1.0" encoding="ISO-8859-1"?>
<gml:LineString>
<gml:coordinates>-7 -7 0 7 -7 0 7 7 0 -7 7 0</gml:coordinates>
</gml:LineString>
XSL 文件:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:gml="http://www.opengis.net/gml">
<xsl:template match="/gml:LineString">
<Transform>
<Shape>
<IndexedFaceSet>
<xsl:attribute name="coordIndex">
<xsl:text>0 1 2 3 -1</xsl:text>
</xsl:attribute>
<Coordinate>
<xsl:attribute name="point">
<xsl:text>
<xsl:value-of select="/gml:coordinates" />
</xsl:text>
</xsl:attribute>
</Coordinate>
</IndexedFaceSet>
</Shape>
</Transform>
</xsl:template>
</xsl:stylesheet>
和 Ajax 脚本(如果属性设置为“/gml:coordinates”的“-7 -7 0 7 -7 0 7 7 0 -7 7 0”,则返回正确的结果):
var xml = document.implementation.createDocument("", "", null);
var xsl = document.implementation.createDocument("", "", null);
xml.async = false;
xsl.async = false;
xml.load("xsl/ajax.xml");
xsl.load("xsl/ajax.xsl");
var processor = new XSLTProcessor();
processor.importStylesheet(xsl);
var output = processor.transformToFragment(xml, document);
document.getElementById("scene").appendChild(output);
提前致谢。