XSLT Transformation!!
Hej,Jeg har en XSLT library der transform en xml til anden. Problemet er at jeg valgte xml som output og der får jeg alt for mange mellem-rum! Hvordan kan jeg slette al mellem-rum?
min xslt kode ser sådan ud:
----------------------------
<xsl:output method="xml" omit-xml-declaration="yes" indent="yes" />
<xsl:template match='path'>
<xsl:element name='path'>
<xsl:attribute name='d'>
<xsl:apply-templates mode='in_path' />
</xsl:attribute>
</xsl:element>
</xsl:template>
<xsl:template match='Move' mode='in_path'>
<xsl:choose>
<xsl:when test='@position="absolute"'>M</xsl:when>
<xsl:otherwise>m</xsl:otherwise>
</xsl:choose>
<xsl:value-of select="x" /><xsl:text>,</xsl:text><xsl:value-of select="y" />
</xsl:template>
<xsl:template match='Line' mode='in_path'>
<xsl:choose>
<xsl:when test='@position="absolute"'><xsl:text>L</xsl:text></xsl:when>
<xsl:otherwise><xsl:text>l</xsl:text></xsl:otherwise>
</xsl:choose>
<xsl:value-of select="x" /><xsl:text>,</xsl:text><xsl:value-of select="y" />
</xsl:template>
<xsl:template match='HLine' mode='in_path'>
<xsl:choose>
<xsl:when test='@position="absolute"'><xsl:text>H</xsl:text></xsl:when>
<xsl:otherwise><xsl:text>h</xsl:text></xsl:otherwise>
</xsl:choose>
<xsl:value-of select='x' />
</xsl:template>
<xsl:template match='VLine' mode='in_path'>
<xsl:choose>
<xsl:when test='@position="absolute"'><xsl:text>V</xsl:text></xsl:when>
<xsl:otherwise><xsl:text>v</xsl:text></xsl:otherwise>
</xsl:choose>
<xsl:value-of select='y' />
</xsl:template>
<xsl:template match='Cubic' mode='in_path'>
<xsl:choose>
<xsl:when test='@position="absolute"'><xsl:text>C</xsl:text></xsl:when>
<xsl:otherwise><xsl:text>c</xsl:text></xsl:otherwise>
</xsl:choose>
<xsl:value-of select='xc1' />
<xsl:choose>
<xsl:when test="number(yc1) < number(0)"><xsl:value-of select='yc1' /></xsl:when>
<xsl:otherwise><xsl:text>,</xsl:text><xsl:value-of select='yc1' /></xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="number(xc2) < number(0)"><xsl:value-of select='xc2' /></xsl:when>
<xsl:otherwise><xsl:text>,</xsl:text><xsl:value-of select='xc2' /></xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="yc2 < 0"><xsl:value-of select='yc2' /></xsl:when>
<xsl:otherwise><xsl:text>,</xsl:text><xsl:value-of select='yc2' /></xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="x < 0"><xsl:value-of select='x' /></xsl:when>
<xsl:otherwise><xsl:text>,</xsl:text><xsl:value-of select='x' /></xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="y < 0"><xsl:value-of select='y' /></xsl:when>
<xsl:otherwise><xsl:text>,</xsl:text><xsl:value-of select='y' /></xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match='SCubic' mode='in_path'>
<xsl:choose>
<xsl:when test='@position="absolute"'>
<xsl:text>S</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>s</xsl:text>
</xsl:otherwise>
</xsl:choose>
<xsl:value-of select='xc2' /><xsl:text>,</xsl:text>
<xsl:value-of select='yc2' /><xsl:text>,</xsl:text>
<xsl:value-of select='x' /><xsl:text>,</xsl:text>
<xsl:value-of select='y' /><xsl:text>,</xsl:text>
</xsl:template>
<xsl:template match='Quadratic' mode='in_path'>
<xsl:choose>
<xsl:when test='@position="absolute"'>
<xsl:text>Q</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>q</xsl:text>
</xsl:otherwise>
</xsl:choose>
<xsl:value-of select='xc' /><xsl:text>,</xsl:text>
<xsl:value-of select='yc' /><xsl:text>,</xsl:text>
<xsl:value-of select='x' /><xsl:text>,</xsl:text>
<xsl:value-of select='y' /><xsl:text>,</xsl:text>
</xsl:template>
<xsl:template match='SQuadratic' mode='in_path'>
<xsl:choose>
<xsl:when test='@position="absolute"'>
<xsl:text>T</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>t</xsl:text>
</xsl:otherwise>
</xsl:choose>
<xsl:value-of select='x' /><xsl:text>,</xsl:text>
<xsl:value-of select='y' /><xsl:text>,</xsl:text>
</xsl:template>
<xsl:template match='Arc' mode='in_path'>
<xsl:choose>
<xsl:when test='@position="absolute"'>
<xsl:text>A</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>a</xsl:text>
</xsl:otherwise>
</xsl:choose>
<xsl:value-of select='rx' /><xsl:text>,</xsl:text>
<xsl:value-of select='ry' /><xsl:text>,</xsl:text>
<xsl:value-of select='rot' /><xsl:text>,</xsl:text>
<xsl:value-of select='lf' /><xsl:text>,</xsl:text>
<xsl:value-of select='sf' /><xsl:text>,</xsl:text>
<xsl:value-of select='x' /><xsl:text>,</xsl:text>
<xsl:value-of select='y' /><xsl:text>,</xsl:text>
</xsl:template>
<xsl:template match='close' mode='in_path'>
<xsl:text>Z</xsl:text>
</xsl:template>
--------------------------------
min source xml fil ser sådan ud:
---------------------------------
<path>
<d>
<Move position="absolute">
<x>0</x><y>312</y>
</Move>
<Cubic position="absolute">
<xc1>40</xc1><yc1>48</yc1><xc2>120</xc2><yc2>-32</yc2><x>160</x><y>-6</y>
</Cubic>
<Cubic position="absolute">
<xc1>0</xc1><yc1>0</yc1><xc2>5</xc2><yc2>4</yc2><x>10</x><y>-3</y>
</Cubic>
<Cubic position="absolute">
<xc1>10</xc1><yc1>-103</yc1><xc2>50</xc2><yc2>-83</yc2><x>90</x><y>-42</y>
</Cubic>
<Cubic position="absolute">
<xc1>0</xc1><yc1>0</yc1><xc2>20</xc2><yc2>12</yc2><x>30</x><y>7</y>
</Cubic>
<Cubic position="absolute">
<xc1>-2</xc1><yc1>12</yc1><xc2>-18</xc2><yc2>17</yc2><x>-40</x><y>17</y>
</Cubic>
<Cubic position="absolute">
<xc1>-55</xc1><yc1>-2</yc1><xc2>-40</xc2><yc2>25</yc2><x>-20</x><y>35</y>
</Cubic>
<Cubic position="absolute">
<xc1>30</xc1><yc1>20</yc1><xc2>35</xc2><yc2>65</yc2><x>-30</x><y>71</y>
</Cubic>
<Cubic position="relative">
<xc1>-50</xc1><yc1>4</yc1><xc2>-170</xc2><yc2>4</yc2><x>-200</x><y>-79</y>
</Cubic>
<close />
</d>
</path>
---------------------------------------------
min xml output ser sådan ud med al de mellem-rum
---------------------------------------------
<path d="
M 0 , 312
C 40 , 48 , 120 -32 , 160 -6
C 0 , 0 , 5 , 4 , 10 -3
C 10 -103 , 50 -83 , 90 -42
C 0 , 0 , 20 , 12 , 30 , 7
C -2 , 12 -18 , 17 -40 , 17
C -55 -2 -40 , 25 -20 , 35
C 30 , 20 , 35 , 65 -30 , 71
c -50 , 4 -170 , 4 -200 -79
Z
"/>
--------------------------------------
xml output skal helst ser sådan ud istedet
--------------------------------------
<path d="M 0,312 C 40,48,120-32,160-6 C 0,0,5,4,10-3 C 10-103,50-83,90-42 C 0,0,20,12,30,7 C-2,12-18,17-40,17 C -55,-2,-40,25,-20,35 C 30,20, 35,65,-30,71 c -50,4,-170,4,-200,-79 Z"/>
altså alt på én linie
er der nogen der kan hjælpe :-)
tak
