I typed my stylesheet directly in the forum editor without testing it.
However when testing now I find that the only error is naming the attribute exclude-result-prefix instead of exclude-result-prefixes.
So the following correction should work fine:
Code:
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"
xmlns:xhtml="http://www.w3.org/1999/xhtml"
xmlns="http://www.w3.org/1999/xhtml"
exclude-result-prefixes="xhtml">
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="xhtml:form">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:attribute name="action">/myserver</xsl:attribute>
<input type="hidden" name="myfield" value="value"/>
<xsl:apply-templates select="node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
When applied to the input XHTML
Code:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Example</title>
</head>
<body>
<form id=".." name=".." action="/dosomething" method="post">
<input type="text" name="foo"/>
<input type="submit"/>
</form>
</body>
</html>
the result with Saxon 6.5 is
Code:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Example</title>
</head>
<body>
<form id=".." name=".." action="/myserver" method="post"><input xmlns:xhtml="http://www.w3.org/1999/xhtml" type="hidden" name="myfield" value="value"/>
<input type="text" name="foo"/>
<input type="submit"/>
</form>
</body>
</html>
I am not sure why you get the error you mention, sounds as if you have moved an instruction to create an attribute to a position where it is not allowed to create an attribute.
As for not copying certain elements, if you want to remove the title element you only need to add the template
Code:
<xsl:template match="xhtml:title"/>
If you don't want to emit an html element then you need to add
Code:
<xsl:template match="xhtml:html">
<xsl:apply-templates/>
</xsl:template>
that makes sure the element is not copied but its children are processed.
--
Martin Honnen
Microsoft MVP - XML