|
Subject: [xsl] xml to xml using look-up-table From: "J. S. Rawat" <jrawat@xxxxxxxxxxxxxx> Date: Fri, 21 Nov 2008 12:44:21 +0530 |
input.xml
<people which="MeAndMyFriends">
<person firstname="Sal" lastname="Mangano">Person one</person>
<person firstname="Sal" lastname="Mangano">Person one</person>
<person firstname="Mike" lastname="Palmieri">Person two</person>
<person firstname="Vito" lastname="Palmieri">Person three</person>
<person firstname="Vinny" lastname="Mari">Person four</person>
</people>copy.xslt
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="node( ) | @*">
<xsl:copy>
<xsl:apply-templates select="@* | node( )"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>TableDrivenRename.xslt
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ren="http://www.ora.com/namespaces/rename"><xsl:import href="copy.xslt"/> <!--Override in importing stylesheet --> <xsl:variable name="lookup" select="/.."/>
<xsl:template match="@*">
<xsl:choose>
<xsl:when test="$lookup/ren:attribute[@from=name(current())]">
<xsl:attribute name="{$lookup/ren:attribute[@from=name(current())]/@to}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:apply-imports/>
</xsl:otherwise>
</xsl:choose>
</xsl:template> <xsl:template match="text()">
<xsl:variable name="input" select="."/>
<xsl:for-each select="$lookup/ren:text">
<xsl:variable name="search-string">
<xsl:value-of select="$lookup/ren:text/@from"/>
</xsl:variable>
<xsl:variable name="replace-string">
<xsl:value-of select="$lookup/ren:text/@to"/>
</xsl:variable>
<xsl:call-template name="search-and-replace">
<xsl:with-param name="input" select="$input"/>
<xsl:with-param name="search-string" select="$search-string"/>
<xsl:with-param name="replace-string" select="$replace-string"/>
</xsl:call-template>
</xsl:for-each>
</xsl:template>| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| [no subject], Unknown | Thread | [xsl] [FO] Truncated line and keep-, Florent Georges |
| [no subject], Unknown | Date | Re: [xsl] Re: Conditional XSL Varia, Andrew Welch |
| Month |