|
Subject: RE: [xsl] Stylesheet from a stylesheet From: "Aron Bock" <aronbock@xxxxxxxxxxx> Date: Mon, 14 Mar 2005 07:57:40 +0000 |
<x> <p a="1">1</p> <q b="2">2</q> </x>
<x> <u><w m="1">1</w></u> <v n="2">2</v> </x>
<xsl:template match="x/p">
<u>
<w>
<xsl:apply-templates select="@*"/>
<xsl:apply-templates/>
</w>
</u>
</xsl:template> <xsl:template match="x/p/@a">
<xsl:attribute name="m">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:template> <xsl:template match="x/q">
<v>
<xsl:apply-templates select="@*"/>
<xsl:apply-templates/>
</v>
</xsl:template> <xsl:template match="x/q/@b">
<xsl:attribute name="n">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:template>
</xsl:stylesheet>
<maps> <map from="/x/p" to="u/w"/> <map from="/x/p/@a" to="@m"/>
<map from="/x/q" to="v"/> <map from="/x/q/@b" to="@n"/> </maps>
<xsl:template match="/"> <xsl:call-template name="write-stylesheet"/> </xsl:template>
<xsl:call-template name="write-identity"/>
<xsl:apply-templates select="/maps/map"/></xsl:element> </xsl:template>
<!-- Writes identity-transform template --> <xsl:template name="write-identity"> <xsl:element name="xsl:template"> <xsl:attribute name="match">node() | @*</xsl:attribute> <xsl:element name="xsl:copy"> <xsl:element name="xsl:apply-templates"> <xsl:attribute name="select">node() | @*</xsl:attribute> </xsl:element> </xsl:element> </xsl:element> </xsl:template>
<!-- Writes the "to" part of each mapping --> <xsl:template name="write-to"> <xsl:param name="to" select="/.."/> <xsl:variable name="path"> <xsl:call-template name="tokenize-path"> <xsl:with-param name="path" select="$to"/> </xsl:call-template> </xsl:variable>
<!-- Continuation of template "write-to"; writes the templates that creates the "to" elements/attributes --> <xsl:template name="write-to-path"> <xsl:param name="path" select="/.."/>
<!-- Calls an utility tokenizing template --> <xsl:template name="tokenize-path"> <xsl:param name="path" select="/.."/> <xsl:call-template name="tokenize"> <xsl:with-param name="string" select="$path"/> <xsl:with-param name="delimiters" select="'/'"/> </xsl:call-template> </xsl:template>
<xsl:choose>
<!-- Nothing to do if empty string -->
<xsl:when test="not($string)" /> <!-- No delimiters signals character level tokenization. -->
<xsl:when test="not($delimiters)">
<xsl:call-template name="_tokenize-characters">
<xsl:with-param name="string" select="$string" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="_tokenize-delimiters">
<xsl:with-param name="string" select="$string" />
<xsl:with-param name="delimiters" select="$delimiters" />
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template><xsl:template name="_tokenize-characters">
<xsl:param name="string" />
<xsl:if test="$string">
<token><xsl:value-of select="substring($string, 1, 1)" /></token>
<xsl:call-template name="_tokenize-characters">
<xsl:with-param name="string" select="substring($string, 2)" />
</xsl:call-template>
</xsl:if>
</xsl:template><xsl:template name="_tokenize-delimiters">
<xsl:param name="string" />
<xsl:param name="delimiters" />
<xsl:param name="last-delimit"/>
<!-- Extract a delimiter -->
<xsl:variable name="delimiter" select="substring($delimiters, 1, 1)" />
<xsl:choose>
<!-- If the delimiter is empty we have a token -->
<xsl:when test="not($delimiter)">
<token><xsl:value-of select="$string"/></token>
</xsl:when>
<!-- If the string contains at least one delimiter we must split it -->
<xsl:when test="contains($string, $delimiter)">
<!-- If it starts with the delimiter we don't need to handle the -->
<!-- before part -->
<xsl:if test="not(starts-with($string, $delimiter))">
<!-- Handle the part that comes befor the current delimiter -->
<!-- with the next delimiter. If ther is no next the first test -->
<!-- in this template will detect the token -->
<xsl:call-template name="_tokenize-delimiters">
<xsl:with-param name="string"
select="substring-before($string, $delimiter)" />
<xsl:with-param name="delimiters"
select="substring($delimiters, 2)" />
</xsl:call-template>
</xsl:if>
<!-- Handle the part that comes after the delimiter using the -->
<!-- current delimiter -->
<xsl:call-template name="_tokenize-delimiters">
<xsl:with-param name="string"
select="substring-after($string, $delimiter)" />
<xsl:with-param name="delimiters" select="$delimiters" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<!-- No occurances of current delimiter so move on to next -->
<xsl:call-template name="_tokenize-delimiters">
<xsl:with-param name="string"
select="$string" />
<xsl:with-param name="delimiters"
select="substring($delimiters, 2)" />
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| [xsl] Stylesheet from a stylesheet, Midsummer Sun | Thread | Re: [xsl] Stylesheet from a stylesh, Midsummer Sun |
| [xsl] Validating an xml aginst wsdl, babu.eshwaramoorthy | Date | Re: [xsl] Stylesheet from a stylesh, Midsummer Sun |
| Month |