[xsl] How to modify img and href in an xhtml document

Subject: [xsl] How to modify img and href in an xhtml document
From: "Terje Christensen" <terchris@xxxxxxxxxxx>
Date: Thu, 11 Sep 2003 03:03:58 +0200
I have a xml structure. Within that structure there is an html document (/page/document/html/body)
I want to change the img and href tags inside /page/document/html/body in order to make the links work properly. I also need to remove a header and footer from the html document.
The XML input file looks like this:
<body>
<div class="theDocumentHeaderNavBars">
. . . Some tables that must be deleted . . .
</div>
<div>
. . . this is the html document . . .
</div>
<div class="theDocumentFooterNavBars">
. . . Some tables that must be deleted . . .
</div>


I have written templates: for img and a tags. They are similar so I just put the img template here:

<xsl:template match="img">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:attribute name="src">
<xsl:choose>
<xsl:when test="starts-with(@src,'./')"> <!-- if 'src' attribute has relative value -->
<xsl:value-of select="concat(/page/@dataRelRoot,/page/currentItem/@itemFullPath,substring(@src,2))"/>
</xsl:when>
<xsl:when test="starts-with(@src,'http://')"> <!-- if 'src' attribute has absolute value -->
<xsl:value-of select="@src"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat(/page/@dataRelRoot,/page/currentItem/@itemFullPath,'/',@src)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>


The img template works, and replaces the src attribute.


I have written a template for the div tag. I?m just printing a text when top and footer div tags are processed.


<xsl:template match="div">
<xsl:choose>
<xsl:when test="@class = 'theDocumentHeaderNavBars' or @class = 'theDocumentFooterNavBars' ">drop the Top or Bottom headers
</xsl:when>
<xsl:otherwise>
<xsl:copy>
<xsl:copy-of select="."/>
<!-- <xsl:apply-templates select="node()|@*|processing-instruction()"/> -->
</xsl:copy>
</xsl:otherwise>
</xsl:choose>
</xsl:template>




But, how to start the transformation?

I have tried to start the transformation, but I do not get the result I want.

<!-- this creates rubbish - just copies the text no tags for tables and so on
<xsl:template match="/page/document/html/body">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
-->




<!-- This works, but it process the whole xml input file. And is it fast enough?
<xsl:template match="*">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
-->


I hope that you can help me with a basic xslt question.
Thanks
Terje Chr.

_________________________________________________________________
Hotmail snakker ditt språk! http://www.hotmail.msn.com/cgi-bin/sbox?rru=dasp/lang.asp - Få Hotmail på norsk i dag



XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



Current Thread