我有一个 XSLT 文件,我想在其中使用 String 名称空间中的一堆函数。即,http://exslt.org/strings,但该网站似乎不再存在。因此,每当调用 tokenize 函数时,我下面的代码都会失败。
这是我的 XSLT 文件:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet
version="1.0"
xmlns:str="http://exslt.org/strings"
xmlns:kml="http://www.opengis.net/kml/2.2"
xmlns:fn="http://www.w3.org/2005/xpath-functions"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
exclude-result-prefixes="str kml fn xsl">
<xsl:output indent="yes"/>
<xsl:strip-space elements="kml:coordinates" />
<xsl:template match="kml:kml">
<nvg version="1.4.0">
<xsl:apply-templates select="kml:Document"/>
</nvg>
</xsl:template>
<xsl:template match="kml:Document">
<g>
<xsl:copy-of select="@id"/>
<xsl:attribute name="label">
<xsl:value-of select="kml:name"/>
</xsl:attribute>
<xsl:apply-templates select="kml:Folder"/>
<xsl:apply-templates select="kml:Placemark"/>
</g>
</xsl:template>
<xsl:template match="kml:Folder">
<g>
<xsl:copy-of select="@id"/>
<xsl:attribute name="label">
<xsl:value-of select="kml:name"/>
</xsl:attribute>
<xsl:apply-templates select="kml:Folder"/>
<xsl:apply-templates select="kml:Placemark"/>
</g>
</xsl:template>
<xsl:template match="kml:Placemark">
<xsl:apply-templates select="kml:Point"/>
<xsl:apply-templates select="kml:LineString"/>
<xsl:apply-templates select="kml:LinearRing"/>
<xsl:apply-templates select="kml:Polygon"/>
<xsl:apply-templates select="kml:MultiGeometry"/>
</xsl:template>
<xsl:template match="kml:MultiGeometry">
<composite>
<xsl:apply-templates select="kml:Point"/>
<xsl:apply-templates select="kml:LineString"/>
<xsl:apply-templates select="kml:LinearRing"/>
<xsl:apply-templates select="kml:Polygon"/>
</composite>
</xsl:template>
<xsl:template match="kml:Point">
<point>
<xsl:copy-of select="@id"/>
<xsl:attribute name="x">
<xsl:value-of select="str:tokenize(kml:coordinates, ',')[1]"/>
</xsl:attribute>
<xsl:attribute name="y">
<xsl:value-of select="str:tokenize(kml:coordinates, ',')[2]"/>
</xsl:attribute>
<xsl:attribute name="label">
<xsl:value-of select="(../../kml:name | ../kml:name)[last()]"/>
</xsl:attribute>
</point>
</xsl:template>
<xsl:template match="kml:LineString">
<polyline>
<xsl:copy-of select="@id"/>
<xsl:attribute name="points">
<xsl:for-each select="str:tokenize(translate(kml:coordinates, ' 	 ', ' '), ' ')">
<xsl:value-of select="str:tokenize(string(.), ',')[1]"/>,<xsl:value-of select="str:tokenize(string(.), ',')[2]"/><xsl:value-of select="string(' ')"/>
</xsl:for-each>
</xsl:attribute>
<xsl:attribute name="label">
<xsl:value-of select="(../../kml:name | ../kml:name)[last()]"/>
</xsl:attribute>
</polyline>
</xsl:template>
<xsl:template match="kml:LinearRing">
<polygon>
<xsl:copy-of select="@id"/>
<xsl:attribute name="points">
<xsl:for-each select="str:tokenize(translate(kml:coordinates, ' 	 ', ' '), ' ')">
<xsl:value-of select="str:tokenize(string(.), ',')[1]"/>,<xsl:value-of select="str:tokenize(string(.), ',')[2]"/><xsl:value-of select="string(' ')"/>
</xsl:for-each>
</xsl:attribute>
<xsl:attribute name="label">
<xsl:value-of select="(../../kml:name | ../kml:name)[last()]"/>
</xsl:attribute>
</polygon>
</xsl:template>
<xsl:template match="kml:Polygon">
<xsl:if test="kml:innerBoundaryIs">
<composite>
<polygon>
<xsl:copy-of select="@id"/>
<xsl:attribute name="points">
<xsl:for-each select="str:tokenize(translate(kml:outerBoundaryIs/kml:LinearRing/kml:coordinates, ' 	 ', ' '), ' ')">
<xsl:value-of select="str:tokenize(string(.), ',')[1]"/>,<xsl:value-of select="str:tokenize(string(.), ',')[2]"/><xsl:value-of select="string(' ')"/>
</xsl:for-each>
</xsl:attribute>
<xsl:attribute name="label">
<xsl:value-of select="(../../kml:name | ../kml:name)[last()]"/>
</xsl:attribute>
</polygon>
<xsl:for-each select="kml:innerBoundaryIs/kml:LinearRing">
<polygon label="Hole">
<xsl:attribute name="points">
<xsl:for-each select="str:tokenize(translate(kml:coordinates, ' 	 ', ' '), ' ')">
<xsl:value-of select="str:tokenize(string(.), ',')[1]"/>,<xsl:value-of select="str:tokenize(string(.), ',')[2]"/><xsl:value-of select="string(' ')"/>
</xsl:for-each>
</xsl:attribute>
</polygon>
</xsl:for-each>
</composite>
</xsl:if>
<xsl:if test="not(kml:innerBoundaryIs)">
<polygon>
<xsl:copy-of select="@id"/>
<xsl:attribute name="points">
<xsl:for-each select="str:tokenize(translate(kml:outerBoundaryIs/kml:LinearRing/kml:coordinates, ' 	 ', ' '), ' ')">
<xsl:value-of select="str:tokenize(string(.), ',')[1]"/>,<xsl:value-of select="str:tokenize(string(.), ',')[2]"/><xsl:value-of select="string(' ')"/>
</xsl:for-each>
</xsl:attribute>
<xsl:attribute name="label">
<xsl:value-of select="(../../kml:name | ../kml:name)[last()]"/>
</xsl:attribute>
</polygon>
<xsl:for-each select="kml:innerBoundaryIs/kml:LinearRing">
<polygon label="Hole">
<xsl:attribute name="points">
<xsl:for-each select="str:tokenize(translate(kml:coordinates, ' 	 ', ' '), ' ')">
<xsl:value-of select="str:tokenize(string(.), ',')[1]"/>,<xsl:value-of select="str:tokenize(string(.), ',')[2]"/><xsl:value-of select="string(' ')"/>
</xsl:for-each>
</xsl:attribute>
</polygon>
</xsl:for-each>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
这个用于将 KML 转换为矢量图形的文件是由某人提供给我的,而该文件是由某人提供给我的,所以基本上所有内容都在翻译中丢失了。
如果可能的话,任何帮助都将非常有价值。
谢谢
EXSLT 规范已移至 http://exslt.github.io
但是,您的代码失败的原因并不是因为规范发生了变化,而是因为您想要的功能没有在您选择的 XSLT 处理器中实现(或配置)。
如今,您可能会发现很容易找到实现 XSLT 2.0 的处理器,该处理器在标准函数命名空间中具有
tokenize
函数。在 2007 年 XSLT 2.0 标准化之前,EXSLT 基本上是一种权宜之计。