Jump to content
sacha74

[XSLT 1.0] Copy and replace

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.

Share this post


Link to post
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>

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...