2012-06-05 3 views
0

다른 모든 쉼표를 XML 출력의 공백으로 바꿔야합니다. XSL에서 공백으로 쉼표를 바꾸는 방법

-0.52437106918239,0.391509433962264,-0.533805031446541,0.430817610062893,0 
-0.547955974842767,0.427672955974843, 

내가 같이 내 XML 출력의 좌표가 필요합니다 :

-0.52437106918239 0.391509433962264, -0.533805031446541 0.430817610062893,0 
-0.547955974842767 0.427672955974843 

가 어떻게 XSLT는이 작업을 수행하는 데 사용할 수있는 지금, 나는 다음과 같습니다 위도와 경도를 가지고? 여기 내 xsl입니다 :

<?xml version="1.0" encoding="ISO-8859-1"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  
xmlns:kml="http://www.opengis.net/kml/2.2"> 
<xsl:output method="text"/> 

<xsl:template match="/"> 
<xsl:apply-templates select="kml:kml/kml:Document/kml:Placemark/kml:Polygon 
/kml:outerBoundaryIs/kml:LinearRing"/> 
</xsl:template> 

    <xsl:template match="kml:LinearRing"> 
"POLYGON((<xsl:value-of select="kml:coordinates"/>))" 
</xsl:template> 
</xsl:stylesheet> 

답변

1

XSLT 2.0에서는 사소한 것입니다. replace()을 사용할 수 있습니다.

XSLT 1.0에서는 이와 같이 템플릿을 사용할 수 있습니다. 매초마다 쉼표를 교체해야하는 목록의 변환 공간 템플릿을 호출하십시오.

<xsl:template name="convert-space"> 
    <xsl:param name="text"/> 
    <xsl:choose> 
    <xsl:when test="contains($text,',')"> 
     <xsl:value-of select="substring-before($text,',')"/> 
     <xsl:value-of select="' '"/> 
     <xsl:call-template name="convert-comma"> 
     <xsl:with-param name="text" select="substring-after($text,',')"/> 
     </xsl:call-template> 
    </xsl:when> 
    <xsl:otherwise> 
     <xsl:value-of select="$text"/> 
    </xsl:otherwise> 
    </xsl:choose> 
</xsl:template> 

<xsl:template name="convert-comma"> 
    <xsl:param name="text"/> 
    <xsl:choose> 
    <xsl:when test="contains($text,',')"> 
     <xsl:value-of select="substring-before($text,',')"/> 
     <xsl:value-of select="','"/> 
     <xsl:call-template name="convert-space"> 
     <xsl:with-param name="text" select="substring-after($text,',')"/> 
     </xsl:call-template> 
    </xsl:when> 
    <xsl:otherwise> 
     <xsl:value-of select="$text"/> 
    </xsl:otherwise> 
    </xsl:choose> 
</xsl:template> 
관련 문제