473,395 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

XSLT: how to process whole document??

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
Jul 20 '05 #1
1 3659


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:output 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.
--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Phil | last post by:
Hi everybody, I am a XSLT beginner and the following problem really makes me crazy ! I have a main "contacts.xml" document which contains references to several contact data XML files. My aim...
4
by: Stephen | last post by:
I have the following that outputs an xml file to a div using ajax: <script type="text/javascript"> function ajaxXML(url,control_id){ if (document.getElementById) { var x =...
3
by: Teksure | last post by:
Hi group, searching in the Internet I found two products for XML which incorporate a very robust debugger for XSL/XSLT, I would like you to see these products and then, give me your opinion about...
4
by: dar_imiro | last post by:
Hi, I'm trying to get rid of frames as menu holder in my html-page. I'd also like to separate the menu structure to xml and xslt. Also the actual content is divided to xml and its corresponding...
3
by: msnews.microsoft.com | last post by:
Hi Does anybody know if XSLT can process several XML file at a time I have two xml document which stored in memory stream and wanna to combine it together under several rules. I am tring to...
3
by: thomas.porschberg | last post by:
Hi, I want to read records from a database and export it in an arbitrary format. My idea was to feed a class with a String array fetched from the database and let this class fire SAX events as...
6
by: Pete Verdon | last post by:
Summary: Can I do an XSLT transform, in the client, of a tree of nodes taken from the displayed page DOM in IE? This works in Firefox. Hi, I'm just starting the process of rewriting part of a...
12
by: Chris | last post by:
Hi, Just wondering if anyone out there knows if it is possible to convert a CSV to xml using XSLT? I've seen a lot of examples of xml to CSV, but is it possible to go back the other way? I...
3
by: super.raddish | last post by:
Greetings, I am relatively new to, what I would call, advanced XSLT/XPath and I am after some advice from those in the know. I am attempting to figure out a mechanism within XSLT to compare the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.