XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 28th, 2004, 11:31 AM
iamaman iamaman is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 5 iamaman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Text Block within XML using XSLT

I'm attempting to insert a text copy of the original xml document into another xml document I'm creating for use as database input using XSLT. My specific requirements require that I comment out the DOCTYPE first, then copy the rest of the original document into the result xml as one large text block. Following is the XSL I've created to do this.

<xsl:template>
<xsl:if test="boolean(true()) = //comment()[contains(.,'DOCTYPE')]" >
<xsl:call-template name="comment_doctype" />
<xsl:call-template name="copy_message_body" />
</xsl:if >

<xsl:template name="comment_doctype" >
<xsl:variable name="d" select="//comment()[contains(.,'DOCTYPE')]" />
<xsl:comment>
<xsl:value-of select="$d" />
</xsl:comment>
</xsl:template>

<xsl:template name="copy_message_body">
<xsl:copy-of select="/root" />
</xsl:template>


Here's what I'm trying to accomplish:

<a>
<b>
Text of the original xml including commented DOCTYPE.
</b>
</a>

My first thought was to encompass the <xsl:call-template> calls from the main template with <xsl:text> elements, but I'm coming up with "unexpected child" errors when I'm testing the XLST.

If anyone has any suggestions on how to accomplish this, they would be greatly appreciated. And if I'm making no sense at all, someone also please bring that to my attention.

Thanks again.

Reply With Quote
  #2  
Old January 28th, 2004, 12:52 PM
MattSidesinger's Avatar
MattSidesinger MattSidesinger is offline
Java PHP Oracle Developer
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: C-Bus OH-IO
Posts: 204 MattSidesinger User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 26 sec
Reputation Power: 5
Send a message via AIM to MattSidesinger
Solution

Try the following. My input XML that I used for testing did not have a !DOCTYPE in it. I don't see why the following code would include it in its output. Let me know whether or not this is a suitable solution.

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

<xsl:template match="/">
	<a>
		<b>
			<!-- the input XML will be printed here -->
			<xsl:apply-templates select="child::node()"/>
		</b>
	</a>
</xsl:template>

<xsl:template match="*">
   <xsl:copy>
      <xsl:copy-of select="@*" />
      <xsl:apply-templates />
   </xsl:copy>
</xsl:template>

<xsl:template match="comment()|processing-instruction()">
   <xsl:copy />
</xsl:template>

</xsl:stylesheet>

Reply With Quote
  #3  
Old January 28th, 2004, 01:29 PM
iamaman iamaman is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 5 iamaman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hey Matt. Thanks for looking into this for me. I'm actually wanting to put the embedded XML document into a database and want to see the entire document "as is". The complication is that my parser (in-house) won't recognize comment fields and will strip them out. That's why I'm attempting to copy the original document as a text field (to trick the parser and have it not parse the text xml subset). I'm looking for something like a CDATA block, but in just general text. Or, xml that is completely escaped out.

What do you think? Is this doable? I have my doubts.

Reply With Quote
  #4  
Old February 2nd, 2004, 02:12 PM
iamaman iamaman is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 5 iamaman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Use Namespaces Possibly?

I'm not too familiar with using namespaces, but I'm wondering if this would make a fitting time to learn. If I put the needed xml block into it's own namespace, maybe I could treat that block differently within my java application?

Any thoughts?

Reply With Quote
  #5  
Old February 2nd, 2004, 02:49 PM
MattSidesinger's Avatar
MattSidesinger MattSidesinger is offline
Java PHP Oracle Developer
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: C-Bus OH-IO
Posts: 204 MattSidesinger User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 26 sec
Reputation Power: 5
Send a message via AIM to MattSidesinger
I believe that even with different namespaces that your parser will still remove comments from the XML block.

I am curious to know what the value of the <b> element is when read into your Java program after the XSL transformation if you modify the above template to the following (depending on how your parser treats the CDATA section the XML in the b element may be preserved or the < and > may be converted to < and >):

Code:
<xsl:template match="/">
	<xsl:variable name="START_CDATA" select="'<![CDATA['"/>
	<xsl:variable name="END_CDATA" select="']]>'"/>
	<a>
		<b>
			<xsl:value-of disable-output-escaping="yes" select="$START_CDATA"/>
			<xsl:apply-templates select="child::node()"/>
			<xsl:value-of disable-output-escaping="yes" select="$END_CDATA"/>
		</b>
	</a>
</xsl:template>


If that does not work, well, I am out of ideas.

Reply With Quote
  #6  
Old February 3rd, 2004, 12:40 PM
iamaman iamaman is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 5 iamaman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks again. I think the CDATA section is where I should have been looking all along. Your suggestion is going to work perfectly. Now I'm just faced with the possibility for nested CDATA sections which I've read is not a good thing. It looks like more work for me to keep plugging through this thing.

Reply With Quote
  #7  
Old February 3rd, 2004, 12:44 PM
MattSidesinger's Avatar
MattSidesinger MattSidesinger is offline
Java PHP Oracle Developer
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: C-Bus OH-IO
Posts: 204 MattSidesinger User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 26 sec
Reputation Power: 5
Send a message via AIM to MattSidesinger
> Now I'm just faced with the possibility for nested CDATA sections which I've read is not a good thing.

Nested CDATA sections are against the spec. If an XML parser does not error out (or provide some other unwanted result) then it is in violation.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > Text Block within XML using XSLT


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT