I have a xml-structure thar looks a little like this:
<Page>
<Id>Page1</Id>
<Content>
<Header>This is the Header</Header>
<Body>This is the body</Body>
<Nested>
<NestedItem>
<Id>N1</Id>
<Content>This is a nested element</Content>
</NestedItem>
<NestedItem>
<Id>N2</Id>
<Content>This too is a nested element</Content>
</NestedItem>
</Nested>
</Content>
<Localizations>
<Localization>
<Locale>ES</Locale>
<Content>
<Header>Esta un caballo</Header>
<Body>Esta body</Body>
<Nested>
<NestedItem>
<Id>N2</Id>
<Content>Esta una element nestado</Content>
</NestedItem>
</Nested>
</Content>
<Localization>
</Localizations>
</Page>
and after xslt-transformation, into which i pass the variable "ES", in this case, i want it to look something like this:
<Page>
<Id>Page1</Id>
<Content>
<Header>Esta un caballo</Header>
<Body>Esta body</Body>
<Nested>
<NestedItem>
<Id>N1</Id>
<Content>This is a nested element</Content>
</NestedItem>
<NestedItem>
<Id>N2</Id>
<Content>Esta una element nestado</Content>
</NestedItem>
</Nested>
</Content>
</Page>
ie, i want to translate the elemnts that have corresponding elements in the Localization, but keep the original text where there is orginal text. The thing is that the structure of the content-element might be unknown, so i cant use specific tag-names in the xsl-file.
so far, i've come up whith this:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="utf-8" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/>
<xsl:param name="locale"></xsl:param>
<xsl:template match="/" name="foo">
<xsl:for-each select="./*">
<xsl:if test="name() != 'Localizations'">
<xsl:element name="{name()}">
<xsl:variable name="elementName" select="name()"/>
<xsl:variable name="elementId" select="Id"/>
<xsl:variable name="elementContent">
<xsl:value-of select="./text()" />
</xsl:variable>
<xsl:variable name="localContent">
<xsl:for-each select="./ancestor::Page[1]/Localizations/Localization">
<xsl:if test="./Locale = $locale">
<xsl:copy-of select="*[name()=$elementName]/*"/>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:copy-of select="$localContent"/>
<xsl:call-template name="foo"/>
</xsl:element>
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Which outputs the xml allright, but it creates duplicates of the elements in the content-tag, and only the spanish content, the other tags remain empty. Am I at all going the right way about this? Any pointers would be appriciated, guides to xslt is quite hard to find and i'm trying to teach myself here...