
June 20th, 2011, 10:27 AM
|
|
|
xml for test
Code:
<?xml version="1.0"?>
<root>
<item>abcdefghijklm</item>
<item>12345678901234</item>
</root>
xsl rekursion
Code:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes" method="xml"/>
<xsl:template match="/">
<root>
<xsl:apply-templates select="root"/>
</root>
</xsl:template>
<xsl:template match="root">
<xsl:apply-templates select="item"/>
</xsl:template>
<xsl:template match="item">
<xsl:call-template name="allfour">
<xsl:with-param name="content" select="."/>
</xsl:call-template>
</xsl:template>
<xsl:template name="allfour">
<xsl:param name="content"/>
<xsl:param name="select" select="''"/>
<xsl:choose>
<xsl:when test="string-length($content) >4">
<xsl:call-template name="allfour">
<xsl:with-param name="content" select="substring($content,5)"/>
<xsl:with-param name="select" select="concat($select,substring($content,1,4),'/')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<result>
<xsl:value-of select="concat($select,substring($content,1))"/>
</result>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
result
Code:
<?xml version='1.0' ?>
<root>
<result>abcd/efgh/ijkl/m</result>
<result>1234/5678/9012/34</result>
</root>
__________________
Helmut Hagemann Germany
fallen to the bottom of the facts?
I reach my hand and we go together
wer lesen und google kann ist klar im Vorteil
who read and google is able is clear in the advantage
|