Johannes Koch wrote:
> Hi there,
>
> I'd like to apply an xpath to both HTML and XHTML documents. First I
> create a DOM document with a Java DOM parser, then apply the xpath with
> Xalan's XPathAPI class. The problem is that in HTML DOM element names
> are all upper-case, whereas in Core DOM (used for the XHTML documents)
> element names are lower-case. When I use a lower-case xpath, e.g.
>
> /head[@profile='http://www.example.org/MyProfile']
>
> it won't match with a head element in an HTML document. OTOH, when I use
>
> /HEAD[@profile='http://www.example.org/MyProfile']
>
Hi,
You could write a pre-processor XSL program that converts all uppercase
tags to lower-case tags. And then feed the output to your regular
program. Shown below is an example of such a pre-processor (warning :
not extensively tested. use at your own risk) :
<?xml version="1.0"?>
<xsl:stylesheet version="2.0"
xmlns

sl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="*">
<xsl:variable name="elementName"
select="translate(local-name(),'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklm nopqrstuvwxyz')"
/>
<xsl:element name="{$elementName}">
<xsl:for-each select="@*">
<xsl:apply-templates select="." />
</xsl:for-each>
<xsl:apply-templates />
</xsl:element>
</xsl:template>
<xsl:template match="@*">
<xsl:variable name="attrName"
select="translate(local-name(),'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklm nopqrstuvwxyz')"
/>
<xsl:attribute name="{$attrName}">
<xsl:value-of select="." />
</xsl:attribute>
</xsl:template>
<xsl:template match="text()">
<xsl:value-of select="." />
</xsl:template>
</xsl:stylesheet>
Regards,
Kenneth