R
Rainer Herbst
Hi *,
please consider the following problem:
I have a XML document which includes some html elements.
I want to replace only the <div> element:
I specified two templates, one matches everything ("*"),
one matches only the "div". As far as I understand, the most specific
rule should apply, i.e. the div rule if the element is a <div>.
But the div rule is never applied! Where is my mistake?
TIA!
Rainer Herbst
The XML document:
<?xml version="1.0" encoding="UTF-8"?>
<page>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="HTML Tidy, see www.w3.org" name="generator"/>
<meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type"/>
<meta content="index" name="robots"/>
<meta content="Universitaet Potsdam" name="keywords"/>
<meta content="Microsoft FrontPage 4.0" name="GENERATOR"/>
<meta content="FrontPage.Editor.Document" name="ProgId"/>
<link href="http://www.uni-potsdam.de/over/unilogol.ico" rel="shortcut
icon"/>
<title>Homepage der Universität Potsdam</title>
</head>
<body vlink="#808080" link="#336699" bgcolor="#ffffff">
<div>wrong!!!</div>
<p align="center">unterschrift</p>
</body>
</html>
<dir:directory xmlns:dir="http://apache.org/cocoon/directory/2.0"
name="pressemitteilungen" lastModified="1064833858000" date="29.09.03
13:10" size="4096" sort="name" reverse="false" requested="true">
<dir:file name="first.xml" lastModified="1064833858000" date="29.09.03
13:10" size="62"/>
</dir:directory>
</page>
My stylesheet:
<?xml version="1.0" standalone="no"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:dir="http://apache.org/cocoon/directory/2.0" >
<!-- all elements -->
<xsl:template match="*">
<xsl:copy select=".">
<xsl:for-each select="@*">
<xsl:attribute name="{name(.)}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:for-each>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="div">
<xsl:for-each
select="/page/dir:directory[@name='pressemitteilungen']/dir:file">
<xsl:value-of select="@name"/>
</xsl:for-each>
</xsl:template>
<xsl:template match="/page">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="dir:directory">
</xsl:template>
</xsl:stylesheet>
--
please consider the following problem:
I have a XML document which includes some html elements.
I want to replace only the <div> element:
I specified two templates, one matches everything ("*"),
one matches only the "div". As far as I understand, the most specific
rule should apply, i.e. the div rule if the element is a <div>.
But the div rule is never applied! Where is my mistake?
TIA!
Rainer Herbst
The XML document:
<?xml version="1.0" encoding="UTF-8"?>
<page>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="HTML Tidy, see www.w3.org" name="generator"/>
<meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type"/>
<meta content="index" name="robots"/>
<meta content="Universitaet Potsdam" name="keywords"/>
<meta content="Microsoft FrontPage 4.0" name="GENERATOR"/>
<meta content="FrontPage.Editor.Document" name="ProgId"/>
<link href="http://www.uni-potsdam.de/over/unilogol.ico" rel="shortcut
icon"/>
<title>Homepage der Universität Potsdam</title>
</head>
<body vlink="#808080" link="#336699" bgcolor="#ffffff">
<div>wrong!!!</div>
<p align="center">unterschrift</p>
</body>
</html>
<dir:directory xmlns:dir="http://apache.org/cocoon/directory/2.0"
name="pressemitteilungen" lastModified="1064833858000" date="29.09.03
13:10" size="4096" sort="name" reverse="false" requested="true">
<dir:file name="first.xml" lastModified="1064833858000" date="29.09.03
13:10" size="62"/>
</dir:directory>
</page>
My stylesheet:
<?xml version="1.0" standalone="no"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:dir="http://apache.org/cocoon/directory/2.0" >
<!-- all elements -->
<xsl:template match="*">
<xsl:copy select=".">
<xsl:for-each select="@*">
<xsl:attribute name="{name(.)}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:for-each>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="div">
<xsl:for-each
select="/page/dir:directory[@name='pressemitteilungen']/dir:file">
<xsl:value-of select="@name"/>
</xsl:for-each>
</xsl:template>
<xsl:template match="/page">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="dir:directory">
</xsl:template>
</xsl:stylesheet>
--