473,657 Members | 2,378 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I preserve XML tags in XSLT transform

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 transform. At the moment the tags
are being ignored. I don't want to put the contents inside CDATA because I
want to be able to parse the xml file as proper xml elsewhere in the
application.

<contentItem>
<title>Stuff about the content</title>
<xhtml>
<h1>Heading</h1>
<p>Para1</p>
<p>Para2</p>
<p>Para3</p>
</xhtml>
</contentItem>

<xsl:output indent="yes" method="xml"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"/>
<xsl:template match="contentI tem">
<title><xsl:val ue-of select="title"/></title>
<xsl:value-of select="xhtml" disable-output-escaping="yes"/>
</xsl:template>

Many thanks
Andrew
Dec 12 '05 #1
3 1755
Andrew Jocelyn wrote:
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 transform. At the moment the tags
are being ignored.

Because you are using xsl:value-of which by definition outputs string
value. Use <xsl:copy-of> instead.

--
Oleg Tkachenko [XML MVP, MCAD]
http://www.XmlLab.Net | http://www.XLinq.Net | http://blog.tkachenko.com
Dec 12 '05 #2
Great, thanks for that. I'm new to this as you can probably tell.

I'm getting the xml namespace attribute added in the output now. Do you know
what controls that?

<p xmlns=""></p>

Thanks again.
Andrew
"Oleg Tkachenko [MVP]" <so**@body.co m> wrote in message
news:43******** ******@body.com ...
Andrew Jocelyn wrote:
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 transform. At the moment the
tags are being ignored.

Because you are using xsl:value-of which by definition outputs string
value. Use <xsl:copy-of> instead.

--
Oleg Tkachenko [XML MVP, MCAD]
http://www.XmlLab.Net | http://www.XLinq.Net | http://blog.tkachenko.com

Dec 12 '05 #3


Andrew Jocelyn wrote:
I'm getting the xml namespace attribute added in the output now. Do you know
what controls that?

<p xmlns=""></p>


If you use xsl:copy-of the element is copied as it is from the input
tree. With the above output I guess your p element in the input was in
no namespace, is copied to the result tree as an element in no namespace
and the serializer which serializes the result tree has to add the
xmlns="" to properly serialize the element.
So either make sure that the input tree defines the namespace you want e.g.
<p xmlns="http://www.w3.org/1999/xhtml">
or your stylesheet processes p elements in no namespace and produces
XHTML elements e.g.
<xsl:template match="p">
<xsl:element name="{local-name()}"
namespace="http ://www.w3.org/1999/xhtml">
<xsl:apply-templates select="@* | node()" />
</xsl:element>
</xsl:template>
Then you can't use xsl:copy but need to use
<xsl:apply-templates />
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Dec 12 '05 #4

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

Similar topics

3
1901
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 this request might be against the spirit of XML in general, but the reason I'm trying to do this is that I want to use XSLT for simple generation of XHTML. Basically I want the page's contents in external files, then I want to include them into a...
4
3161
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 particular tag, and was also pretty sure that they wanted the following <ul><li>two</li><li>items</li></ul> to appear as a list. To make matters worse <sarcastic>how could this be worse?</sarcastic>, the XHTML can be mixed with our own tags.</note>
1
1547
by: bjam | last post by:
Hi, I am trying to create a sort of include file into my xsl files such that calling the following template will push these xml tags into my document such that the other xsl files can use these tags to make decisions. In this case I want antother template that is going to create tables be able to call this template in order to get information for the various table paramaters and then use xsl:attribute to push items into the table tag. ...
4
4817
by: schneider | last post by:
Anyone know if there is a way to dynamicly create a Xslt template/s and use them as an xml transform with-out use files for the Xslt? All the methods I see use files. I want to create a Xslt transform via code? Any examples would be great.
2
2261
by: Andy | last post by:
Hi, I have an ASP.NET webpage that contains an ASP.NET XML control. This control accepts an XSLT stylesheet and XML document which it then uses to render HTML code where the XML control is positioned for the client at the server. This setup works great for an XSLT stylesheet that generates plain HTML tags. But, this doesn't work so well if I use ASP.NET tags (such as <asp:dropdownlist>) inside the stylesheet. Although the code for the...
1
8025
by: mikepmyers | last post by:
I've done some research online and turned up with results that did not sit well with me. I’m using the System.Xml.XslCompiledTransform class as recommended by MS; however, it’s creating self-closing tags that I don’t want, example: * My XSLT has: <script language="javascript" src="client_scripts/VehInInv.js"></script> * Using the XslCompiledTransform class I get: <script language="javascript" src="client_scripts/VehInInv.js"/> -- notice...
4
3123
by: n.phelge | last post by:
I need to perform an XSLT to set the namespace on some XML and I need to preserve the original document line formatting to assist with error handling (so the line number from any schema validation error matches the original line number). The original XML looks like this: <Head> <Body Val1="10" Val2="11" /> </Head>
18
6530
by: malathib | last post by:
Hi, while trasforming xml to html using xslt, i dont want to lose xml tags.I want to preserve it. After transforming to html and displaying in browser and if you are right clicking and viewing the source, xml tags will be there as it is but it will display teh content as html in browser. But after transforming, when i am displaying in text editor, the xml tags are getting lost. Could anybody help me in this regard. Regards, Malathi
1
1743
by: mahendra dubey | last post by:
Hi there I am using XSLT to process an XML file.I want to copy all whole XML and want to modify some attribute node.I using follwing code <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl" xmlns:db="http://tempuri.org/DatabaseXMLSchema.xsd"> <xsl:output method="xml"...
0
8732
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8504
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7337
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6169
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4318
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2732
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1959
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1622
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.