Chciałbym, aby tenzmianę nazw elementu z XSLT
<hello>
<one>
<paragraph>p1</paragraph>
</one>
</hello>
w tym
<x:hello y:an_attribute="a value for an_attribute" xmlns:x="some_new_namespace" xmlns:y="other_ns">
<one>
<paragraph>p1</paragraph>
</one>
</x:hello>
jest to arkusz stylów wymyśliłem:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:param name="element_localname" select="'hello'"/>
<xsl:template match="node()">
<xsl:choose>
<xsl:when test="local-name() = $element_localname">
<xsl:element name="{$element_localname}" namespace="some_new_namespace">
<xsl:attribute name="an_attribute" namespace="other_ns">a value for an_attribute</xsl:attribute>
<xsl:apply-templates select="node()"/>
</xsl:element>
</xsl:when>
<!-- copy the rest as is -->
<xsl:otherwise>
<xsl:copy>
<xsl:apply-templates select="node()" />
</xsl:copy>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
ale z jakiegoś dziwnego powodu atrybut dodawany do elementu ma taką samą przestrzeń nazw jak sam element główny? czemu?
<ns0:hello xmlns:ns0="other_ns" ns0:an_attribute="a value for an_attribute">
<one>
<paragraph>p1</paragraph>
</one>
</ns0:hello>
Dziękuję za przeczytanie.
Running źródło pośrednictwem transformacji xsltproc daje mi ' "dla elementu' hello', który wydaje się być tym, czego potrzebujesz. Zastanawiam się, czy to jest XSL 1.0 versus XSL 2.0? –
Dzięki za próby. Używam eclipse wtp build w procesorze xslt. Nie mam pojęcia, jakiej implementacji używa. – Luca
Dobre pytanie, +1. Zobacz moją odpowiedź na znacznie prostsze i krótsze rozwiązanie niż obecnie akceptowane. :) –