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 April 25th, 2006, 12:16 AM
Authorized User
 
Join Date: Apr 2006
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default Some insertions and deletions in XML file

Hello all,

Could anyone please help me with the following

This is my "Input XML" file
===========================
<?xml:stylesheet type="text/xsl" href="a-1.xsl"?>

<!DOCTYPE article SYSTEM "entity.dtd">
<hdbkedit>
<article id="A0003971" access.no="V14A_D01_A01" status="draft" lang="en">
<article.info>
<page.no type="page">3</page.no>
<title>Bulk-Forming Processes</title>
<cite.as>Introduction to Bulk-Forming Processes, <italic>Bulk Forming</italic>, Vol 14A, <italic>Handbook</italic>International, 2005, p 3&ndash;10</cite.as>
<first.page>3</first.page>
<last.page>10</last.page>
<figct number="6">
<tabct number="1">

I need this as my "Output XML" file
===================================
<?xml:stylesheet type="text/xsl" href="a-1.xsl"?>
<!DOCTYPE article SYSTEM "entity.dtd">
<hdbkedit>
<article id="A0003971" access.no="V14A_D01_A01" status="draft" lang="en">
<article.info>
<page.no type="page">3</page.no>
<title>Bulk-Forming Processes</title>
<cite.as>Introduction to Bulk-Forming Processes, <italic>Bulk Forming</italic>, Vol 14A, <italic>Handbook</italic>International, 2005, p 3&ndash;10</cite.as>
<first.page>3</first.page>
<last.page>10</last.page>
<figct number="6"/>
<tabct number="1"/>


Further explanation to avoid confusion
======================================
I need to insert this line as my first line
<?xml:stylesheet type="text/xsl" href="a-1.xsl"?>

As my second line I need to delete the following line
<!DOCTYPE hdbkedit PUBLIC "-//ASM//DTD HANDBK.DTD 19960930 Ver 3.0//EN" "handbk.dtd">

and instead need to insert the following line
<!DOCTYPE article SYSTEM "entity.dtd">

I need to insert a backslash at the end of my tag
currently I have - <figct number="6">
But I need as - <figct number="6"/>


Thanks



 
Old April 25th, 2006, 03:13 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You need to understand the transformation process better. The XML parser produces a tree of nodes; your XSLT stylesheet transforms this into another tree of nodes; and the serializer converts the result tree back into a text file containing markup.

Copying the processing instruction is straightforward: just use a template rule

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

(PLEASE use indentation in your posted code - it's an elementary courtesy to your readers!)

The

will be dropped automatically because it's a comment node and the default template rule for comments does nothing (it deletes them).

The <!DOCTYPE article> doesn't form part of the tree constructed by the XML parser, so your XSLT stylesheet can't process it. You can ask the serializer to generate a DOCTYPE declaration by using <xsl:output doctype-system="entity.dtd"/>, but there is no way of making this depend on what was in the input document.

<figct number="6"> is not well-formed XML, so it won't make it through the XML parser. XSLT stylesheets can only process well-formed XML. Even if it did make it through, you couldn't add a "/" to the markup (that's a forwards slash, by the way, not a backslash) because the serializer looks after markup issues, your XSLT code is only concerned with the structure of the result tree.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old April 25th, 2006, 04:02 AM
Authorized User
 
Join Date: Apr 2006
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry I was wrong in specifying my Input and Output file. I think my explanation now will be more clear.

This is my Input "SGM" file
===========================
<!DOCTYPE hdbkedit PUBLIC "-//ASM//DTD HANDBK.DTD 19960930 Ver 3.0//EN" "handbk.dtd">
<hdbkedit>
<article id="A0003971" access.no="V14A_D01_A01" status="draft" lang="en">
<article.info>
<page.no type="page">3</page.no>
<title>Bulk-Forming Processes</title>
<cite.as>Introduction to Bulk-Forming Processes, <italic>Bulk Forming</italic>, Vol 14A, <italic>Handbook</italic>International, 2005, p 3&ndash;10</cite.as>
<first.page>3</first.page>
<last.page>10</last.page>
<figct number="6">
<tabct number="1">

I need this as my Output "XML" file
===================================
<?xml:stylesheet type="text/xsl" href="a-1.xsl"?>
<!DOCTYPE article SYSTEM "entity.dtd">
<hdbkedit>
<article id="A0003971" access.no="V14A_D01_A01" status="draft" lang="en">
<article.info>
<page.no type="page">3</page.no>
<title>Bulk-Forming Processes</title>
<cite.as>Introduction to Bulk-Forming Processes, <italic>Bulk Forming</italic>, Vol 14A, <italic>Handbook</italic>International, 2005, p 3&ndash;10</cite.as>
<first.page>3</first.page>
<last.page>10</last.page>
<figct number="6"/>
<tabct number="1"/>


Further explanation to avoid confusion
======================================
I need to insert this as my first line
<?xml:stylesheet type="text/xsl" href="a-1.xsl"?>

As my second line I need to delete the following line
<!DOCTYPE hdbkedit PUBLIC "-//ASM//DTD HANDBK.DTD 19960930 Ver 3.0//EN" "handbk.dtd">

and instead need to insert the below line
<!DOCTYPE article SYSTEM "entity.dtd">

For the empty element (<figct number="6">) I need to insert a forward slash to make it through the XML parser. So that my output will be

<figct number="6"/>


Thanks again








Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple input xml / get data from other xml file elayaraja.s XSLT 3 July 25th, 2008 06:59 AM
VB.net, adding XML data to an existing XML file saikoboarder XML 11 April 17th, 2008 04:19 PM
Wrox CMS Deletions retroviz BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 9 February 3rd, 2007 04:55 AM
DTS Package, XML task. Read XML file and store it Victoria SQL Server DTS 0 July 24th, 2006 02:43 PM
Merge XML files into a xml file using xslt lxu XML 4 November 6th, 2003 06:01 PM





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