473,503 Members | 1,888 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XSL replacing tags from xhtml to xhtml

110 New Member
I have xsl code which I was hoping could be used to replace one specific tag from an xhtml document and output another xhtml document.

xsl has phenomenal potential in data replacing, but coming from C/C++ background, it looks like a functional language I'm not familiar with.

Here's the link to where I got the code (thanks goes to the author), but I don't have a strong enough background in xsl to tell what is going on.

xslfile.xsl
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0"?>
  2.  
  3. <xsl:stylesheet version="2.0"
  4.   xmlns:xhtml="http://www.w3.org/1999/xhtml"
  5.   xmlns="http://www.w3.org/1999/xhtml"
  6.   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  7.   xmlns:xs="http://www.w3.org/2001/XMLSchema"
  8.   exclude-result-prefixes="xhtml xsl xs">
  9.  
  10. <xsl:output method="xml" version="1.0" encoding="UTF-8" doctype-public="-//W3C//DTD XHTML 1.1//EN" doctype-system="http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" indent="yes"/> 
  11.  
  12. <!-- the identity template -->
  13. <xsl:template match="@*|node()">
  14.   <xsl:copy>
  15.     <xsl:apply-templates select="@*|node()"/>
  16.   </xsl:copy>
  17. </xsl:template>
  18.  
  19. <!-- template for the head section. Only needed if we want to change, delete or add nodes. In our case we need it to add a link element pointing to an external CSS stylesheet. -->
  20.  
  21. <xsl:template match="xhtml:head">
  22.   <xsl:copy>
  23.     <link rel="StyleSheet" href="xhtml_test.css" type="text/css"/>
  24.     <xsl:apply-templates select="@*|node()"/>
  25.   </xsl:copy>
  26. </xsl:template>
  27.  
  28. <!-- template for the body section. Only needed if we want to change, delete or add nodes. In our case we need it to add a div element containing a menu of navigation. -->
  29.  
  30. <xsl:template match="xhtml:body">
  31.   <xsl:copy>
  32.  
  33.     <!-- Where I want the code to find all occurrences of
  34.           <span> </span> within the body and replace it with
  35.           <div> </div> (as an example--maybe with attributes included?) -->
  36.  
  37.     <xsl:apply-templates select="@*|node()"/>
  38.   </xsl:copy>
  39. </xsl:template>
  40. </xsl:stylesheet>
  41.  
xslfile.xhtml
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0"?>
  2.  
  3. <?xml-stylesheet type="text/xsl" href="transform.xsl"?> <!-- To view xml in foxfire -->
  4.  
  5. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
  6. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
  7.   <body>
  8.  
  9.   <span width="20%" id="name"> stuff </div>
  10.  
  11.   <!-- rest of html goes here -->
  12.   </body>
  13. </html>
  14.  
I know if I could understand how xsl files are parsed I know I could figure out how xsl works, but to me right now, that's a black box. <xsl:template > seems like a function which <xsl:apply-templates > calls, but tell me if I'm wrong on this.

I would like to figure this out without help, but being stuck learning this has been frustrating. Any help would be greatly appreciated.
Aug 27 '08 #1
1 2636
Dormilich
8,658 Recognized Expert Moderator Expert
I know if I could understand how xsl files are parsed I know I could figure out how xsl works, but to me right now, that's a black box. <xsl:template > seems like a function which <xsl:apply-templates > calls, but tell me if I'm wrong on this.
<xsl:template> indeed is similar to a function.
I recommend reading a XSL tutorial like http://www.w3schools.com/xsl/ and http://www.w3schools.com/xpath/ (you need XPath for accessing the nodes of your xml file you need to process) for a start.
Aug 27 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
1891
by: Francis Hwang | last post by:
Hi, Maybe this is a newbie question, but: Is there a way to output an element's contents -- including contained nodes and free-form text -- without the containing tags? I can imagine that...
4
3147
by: Luke Dalessandro | last post by:
I have some XML data that has mixed content XML tags that embed XHTML tags, for instance: <note>Somebody wrote this note in XHTML and wanto to <a href="link.html" target="_new">link</a> to a...
8
5722
by: Hostile17 | last post by:
Consider the following HTML. ---------- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd"> <html> <head> <meta...
30
3855
by: Toni Mcintyre | last post by:
i'm having 2 problems with the http://validator.w3.org 1. if i have: <meta http-equiv="Content-Script-Type" content="text/javascript"> then why do i need <script type=text/javascript>...
7
1715
by: Rob Meade | last post by:
Hi all, Been a long time since I've been here... /me waves to all.. Ok - my conundrum.. I have a form where a user can enter text and BB codes...for example:
12
17078
by: Stefan Weiss | last post by:
Hi. (this is somewhat similar to yesterday's thread about empty links) I noticed that Tidy issues warnings whenever it encounters empty tags, and strips those tags if cleanup was requested....
3
1748
by: Andrew Jocelyn | last post by:
Hi Is there a way of outputting some xml tags during an XSLT transform? For example when I use the 'xsl:value-of select="xhtml"' statement I'd like to output the children of 'xhtml' after the...
5
2789
by: bram.labarque | last post by:
Hello all, The parsing should happen at the browser. I have three files: 1) Initial file: xml with some data and a pointer to an xsl. <?xml version="1.0" encoding="ISO-8859-1"?>...
1
4489
by: patelgaurav85 | last post by:
Hi, I want to convert xml in one format into another xml format shown below Input xml : <Name> <Name1> <Name11>Name11</Name11> <Name12>Name12</Name12>
0
7205
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
7348
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7006
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
7467
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
5592
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,...
1
5021
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4685
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.