XSLT: how to process whole document??

B

Bartek

Hello

This is my problem:
It consider xml 2 xml conversion.
source document had unknown structure (xhtml),
xslt must process every node, attribute, text, comments etc. from source and
write in destination file.
During that process i must catch some nodes (e.g. <input> position of this
node in XML tree is unknown )and change the value attribute.
The destination xml file must be the exact copy of source file + changes on
value attribute on some nodes.

Where can i find some sample code that can process and write whole context
node by node, comment etc.

thanks for any help
 
M

Martin Honnen

Bartek wrote:

It consider xml 2 xml conversion.
source document had unknown structure (xhtml),
xslt must process every node, attribute, text, comments etc. from source and
write in destination file.
During that process i must catch some nodes (e.g. <input> position of this
node in XML tree is unknown )and change the value attribute.
The destination xml file must be the exact copy of source file + changes on
value attribute on some nodes.

Where can i find some sample code that can process and write whole context
node by node, comment etc.

Start with the identity transformation as described here:
http://www.w3.org/TR/xslt#copying
then add templates for those elements you need to change, here is a
simple example, the XHTML is

<?xml version="1.0" encoding="UTF-8"?>
<html
xmlns="http://www.w3.org/1999/xhtml"
lang="en" xml:lang="en">
<head>
<title>example document to be transformed</title>
</head>
<body>
<form action="whatever.php">
<fieldset>
<legend>Who is GOD?</legend>
<label>
Who is GOD?
<input type="text" name="GOD" value="???" />
</label>
<input type="submit" />
</fieldset>
</form>
</body>
</html>

the XSLT is

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

<xsl:eek:utput method="xml" encoding="UTF-8" />

<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()" />
</xsl:copy>
</xsl:template>

<xsl:template
xmlns:xhtml="http://www.w3.org/1999/xhtml"
match="xhtml:input[@name = 'GOD']">
<xsl:copy>
<xsl:apply-templates select="@*[local-name() != 'value']" />
<xsl:attribute name="value"><xsl:text>Kibo</xsl:text></xsl:attribute>
</xsl:copy>
</xsl:template>

</xsl:stylesheet>

the XHTML output is

<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>example document to be transformed</title>
</head>
<body>
<form action="whatever.php">
<fieldset>
<legend>Who is GOD?</legend>
<label>
Who is GOD?
<input type="text" name="GOD" value="Kibo"/>
</label>
<input type="submit"/>
</fieldset>
</form>
</body>
</html>

so the value attribute has been changed.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top