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 December 23rd, 2003, 09:40 AM
Authorized User
 
Join Date: Nov 2003
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default Efficiently Breaking Out of Parent

Following is the source XML that I am transforming. As you can see, the <text:a> tag is a child of the <text:p> tag:
Code:
<text:p text:style-name="Dog_Normal">
   ...the one hand, the national economy had performed...
   <text:a xlink:type="simple" xlink:href="http://www.atomicdog.com/" office:name="Name" office:target-frame-name="_blank" xlink:show="new">prowess</text:a>
   ... or his ability to ...
</text:p>
According to my companies DTD, the XML containing links should not be nested in paragraph text nodes. So ideally, I would like to transfrom the above XML into this:

Code:
<Dog_Normal>
   ...the one hand, the national economy had performed...
</Dog_Normal>
<Dog_Link>
   <Dog_URL>http://www.atomicdog.com/</Dog_URL>
   <Dog_Reference>prowess</Dog_Reference>
</Dog_Link>
<Dog_Normal>
   ... or his ability to ...
</Dog_Normal>
So my question is, is there an efficient way of "breaking the parent" of the context node? So far I have had a rough time with thinking of a way to do this. My first instinct was to do something like this:
Code:
<xsl:template match="<text:a>">
   </Dog_Normal>
   <Dog_Link>...</Dog_Link>
   <Dog_Normal>
</xsl:template>
However, this is malformed XML and does not pass the parser. Any thoughts?

Thanks in advance!
Aaron
 
Old December 24th, 2003, 11:52 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 147
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to armmarti
Default

I suppose that this stylesheet is applied to the XML snippet you posted(as a separate XML document).
I suppose also that all namespace prefixes are properly bound to their namespace URIs:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:text="TEXT" xmlns:xlink="XLINK" xmlns:office="OFFICE" exclude-result-prefixes="text xlink office">
    <xsl:output indent="yes"/>
    <xsl:template match="text:p">
        <xsl:apply-templates/>
    </xsl:template>
    <xsl:template match="text()[parent::text:p]">
        <xsl:element name="{../@text:style-name}">
            <xsl:value-of select="."/>
        </xsl:element>
    </xsl:template>
    <xsl:template match="text:a">
        <Dog_Link>
            <Dog_URL><xsl:value-of select="@xlink:href"/></Dog_URL>
            <Dog_Reference><xsl:value-of select="."/></Dog_Reference>
        </Dog_Link>
    </xsl:template>
</xsl:stylesheet>
If you need to "insert" these template rules to existing stylesheet, you have to be careful: do not let any "interference". If you'll have troubles with that, let me know.

Regards,
Armen





Similar Threads
Thread Thread Starter Forum Replies Last Post
Breaking out of frames takabyte PHP How-To 0 August 6th, 2007 11:31 AM
Breaking the Forums? iPagan BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 7 August 2nd, 2007 02:02 PM
Transaction Where Its Works More Efficiently windows_mss ASP.NET 1.0 and 1.1 Professional 11 March 15th, 2007 05:05 AM
Breaking a String Macsood Intro Programming 1 January 23rd, 2006 01:09 PM
How to export data to excel efficiently????????? avats ADO.NET 0 July 9th, 2005 01:09 PM





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