Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 18th, 2007, 04:41 AM
Authorized User
 
Join Date: Dec 2005
Posts: 71
Thanks: 10
Thanked 0 Times in 0 Posts
Default Markup Text to XML

Dear Team,

Following is my XSLT converter where I use to convert short tag files to Vaild-XML

XSLT

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

<xsl:template match="bk">
<book>
  <xsl:apply-template select="@*"/>
  <xsl:apply-template/>
</book>
</xsl:template>

<xsl:template match="au">
<author>
  <xsl:apply-template select="@*"/>
  <xsl:apply-template/>
</author>
</xsl:template>


Input File:
<bk>Book Name</bk>
<au>author name</au>

Output File:
<book>Book Name</book>
<author>author name</author>

Now the problem is generating element for plain text inside unknown tag sequence. And I want all this to named as <unknown> element

For example:
------------

Input File:
<book>Book Name</book>
Volume-I
<author>author name</author>
Only @ £450

Required Output File:
<book>Book Name</book>
<unknow>Volume-I</unknow>
<author>author name</author>
<unknow>Only @ £450</unknow>

Any help would be great full.

Thanks,
ROCXY





__________________
Thanks,
Rocxy.
 
Old October 18th, 2007, 04:57 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

You're problem is that the text isn't inside a tag at all, its a text node which is a sibling of the bk and au elements.

Something like this might work:

<xsl:template match="bk/text() | au/text()">
  <xsl:value-of select="."/>
</xsl:template>

<xsl:template match="text()">
  <unknown>
    <xsl:value-of select="."/>
  </unknown>
</xsl:template>


/- Sam Judson : Wrox Technical Editor -/
 
Old October 18th, 2007, 04:58 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

I haven't tested the above, but it very much depends on what other text nodes you have, and especially how your parser is handling whitespace.

/- Sam Judson : Wrox Technical Editor -/
 
Old October 18th, 2007, 05:01 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Your input file isn't well-formed XML, so it can't be processed using XSLT. If you add a <wrapper> element around it, to make it well-formed, then you can do

<xsl:template match="wrapper/text()">
<unknown><xsl:value-of select="."/></unknown>
</xsl:template>

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old October 18th, 2007, 05:04 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Unfortunately there's no way in standard XSLT to generate an internal DTD like the one you describe, without using the horrible disable-output-escaping mechanism (you can do it in Saxon using the saxon:doctype extension, but that doesn't help all that much - it has the same architectural problems).

There's no reason why the text that you generate has to be fixed, you can compute it using xsl:value-of in the same way as any other text.

However, there's no obvious way of reading it from the source document, unless you are prepared to use XSLT 2.0's unparsed-text() function to read the document in unparsed form and extract the DOCTYPE definition "by hand".

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
drag-and-drop from toolbox to Markup View Rex777 BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 5 September 22nd, 2008 01:54 PM
Moving markup to different position Pankaj C XSLT 4 February 18th, 2008 06:00 AM
any markup language to XML bcogney XSLT 10 April 16th, 2007 08:39 AM
Unwanted z-index in html markup using VWD VictorVictor ASP.NET 2.0 Basics 3 July 25th, 2006 07:51 AM
XML to text raoulvb XSLT 8 June 6th, 2003 09:16 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.