Substituindo strings em vários arquivos XML
Dado o seguinte arquivo xml com o conhecimento de que a estrutura e o conteúdo podem mudar:
<something>
<parent>
<child>Bird is the word 1.</child>
<child>Curd is the word 2.</child>
<child>Nerd is the word 3.</child>
</parent>
<parent>
<child>Bird is the word 4.</child>
<child>Word is the word 5.</child>
<child>Bird is the word 6.</child>
</parent>
</something>
Gostaria de uma maneira de usar xquery (e até xslt) para substituir todas as instâncias de uma string fornecida por outra. Por exemplo, substitua a palavra "Bird" por "Dog". Portanto, os resultados seriam:
<something>
<parent>
<child>Dog is the word 1.</child>
<child>Curd is the word 2.</child>
<child>Nerd is the word 3.</child>
</parent>
<parent>
<child>Dog is the word 4.</child>
<child>Word is the word 5.</child>
<child>Dog is the word 6.</child>
</parent>
</something>
Eu não tenho ideia se isso é possível. Todas as tentativas que fiz eliminaram as tags. Eu até tentei este exemplo (http://geekswithblogs.net/Erik/archive/2008/04/01/120915.aspx), mas é para o texto não um documento inteiro.
Por favor ajude!
ATUALIZAR
Eu tentei correr com a sugestão xslt 2.0, pois parecia se encaixar melhor. Ao tentar modificá-lo para o meu caso, eu continuo secando.
Eu quero passar em um parâmetro xml para definir as substituições. Então, modificando o xslt assim:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:param name="list">
<words>
<word>
<search>Bird</search>
<replace>Dog</replace>
</word>
<word>
<search>word</search>
<replace>man</replace>
</word>
</words>
</xsl:param>
<xsl:template match="@*|*|comment()|processing-instruction()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="text()">
<xsl:param name="chosen" select="." />
<xsl:for-each select="$list//word">
<xsl:variable name="search"><xsl:value-of select="search" /></xsl:variable>
<xsl:analyze-string select="$chosen" regex="{$search}">
<xsl:matching-substring><xsl:value-of select="replace" /></xsl:matching-substring>
<xsl:non-matching-substring><xsl:value-of select="$chosen"/></xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Os resultados são:
<something>
<parent>
<child>Bird is the word 1.Bird is the word 1.</child>
<child>Curd is the word 2.Curd is the word 2.</child>
<child>Nerd is the word 3.Nerd is the word 3.</child>
</parent>
<parent>
<child>Bird is the word 4.Bird is the word 4.</child>
<child>Word is the word 5.Word is the word 5.</child>
<child>Bird is the word 6.Bird is the word 6.</child>
</parent>
</something>
Escusado será dizer, mas, eu não quero duplicado e também incorreto.
Por favor ajude!