Jump to content

[XSLT 1.0] Copy and replace


sacha74

Recommended Posts

Hello,I have a xml file and what I want to do is to copy the entire file with all the tags. I've done this with :

<xsl:template match="node()">   <xsl:copy>	   <xsl:apply-templates select="node()"/>   </xsl:copy></xsl:template>

But I also want to replace all characters "ÁÉÍÓÚ" with"AEIOU". I managed to do this with :

<xsl:variable name="Schar">ÁÉÍÓÚ</xsl:variable><xsl:variable name="Rchar">AEIOU</xsl:variable>	<xsl:template match="node()">	<xsl:copy-of select="translate(normalize-space(.), $Schar, $Rchar)"></xsl:copy-of></xsl:template>

The problem with this last code is that there are no more tags in the result file. But what Iwant is to combine the two features that are : copying the xml file while only changing the characters mentionned above.With an example, I would like that :

<xml><table><ROW><CELL ROWSPAN="1" COLSPAN="1"><Tableau-cellule><A ID="pgfId-594128"></A>Ámbito </Tableau-cellule></CELL>......</ROW></table></xml>

to become that :

<xml><table><ROW><CELL ROWSPAN="1" COLSPAN="1"><Tableau-cellule><A ID="pgfId-594128"></A>Ambito </Tableau-cellule></CELL>......</ROW></table></xml>

Can somebody telle me how to combine these two rules because when I tried to combine them , everytime one of two doesn't work. :) Thanks in advance for all the help I can find.

Link to comment
Share on other sites

<xsl:template match="*">  <xsl:copy>	<xsl:apply-templates select="@* | node()"/>  </xsl:copy></xsl:template><xsl:template match="@*">  <xsl:attribute name="{name()}" namespace="{namespace-uri()}">	 <xsl:value-of select="translate(., $Schar, $Rchar)"/>  </xsl:attribute></xsl:template><xsl:template match="text()">   <xsl:value-of select="translate(., $Schar, $Rchar)"/></xsl:template><xsl:template match="comment() | processing-instruction()">  <xsl:copy/></xsl:template>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...