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 August 27th, 2012, 09:36 PM
Registered User
 
Join Date: Aug 2012
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Question Help needed transforming XML using multiple XSLT files.

Hello All,

I’m trying to keep my XSLT files small and maintainable by performing a series of transformations on my XML using multiple XSLT files. My issue is that the last XSLT transformation seems to override the previous XSLT transformation.

In this example, when I attempt to transform the XML using Main.xslt, Chapters.xslt and finally Intro.xslt, the results only show the Intro tags (all book and chapter tags are removed).

Does anyone know where I am going wrong (also, please forgive my - I haven't compiled the example to test it - it is only intended as an example).

Yes, I am new to this.

Something like this:

<book>
<intro>This is an intro to the book</intro>
<chapter>
<content>First chapter text</content>
</chapter>
<chapter>
<content>Second chapter text</content>
</chapter>
<chapter>
<content>Last chapter text</content>
</chapter>
</book>


Main.xslt
<xsl:stylesheet: version=”1.0” xmlns:xsl=”http://www.w3.org/1999/XSL/Transform”>
<xsl:template match=”/”>
<Book>
<Intro/>
<Chapters/>
</Book>
</xsl:template>
</xsl:stylesheet>


Chapters.xslt
<xsl:stylesheet: version=”1.0” xmlns:xsl=”http://www.w3.org/1999/XSL/Transform”>
<xsl:template match=”Chapters”>
<xsl:for-each select=”book/chapter”>
<xsl:value-of select=”content”/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>


Intro.xslt
<xsl:stylesheet: version=”1.0” xmlns:xsl=”http://www.w3.org/1999/XSL/Transform”>
<xsl:template match=”Intro”>
<xsl:value-of select=”book/intro”/>
</xsl:template>
</xsl:stylesheet>
 
Old August 28th, 2012, 04:10 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 add an identity template to each stylesheet, so that elements that aren't matched are copied over unchanged:

Code:
<xsl:template match="*>
  <xsl:copy><xsl:copy-of select="@*"/><xsl:apply-templates/></xsl:copy>
</xsl:template>
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
The Following User Says Thank You to mhkay For This Useful Post:
LenovoThinkCentre (August 28th, 2012)
 
Old August 28th, 2012, 06:38 AM
Registered User
 
Join Date: Aug 2012
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Smile

Dear Michael,

I can't express how thankful I am for your super-fast and super-awesome help. I did exactly what you said and it fixed all of my issues. My "pipeline" framework is now buzzing and transformations are flying :-)!

I don't know how much time and stress you have saved me, but I'm certain it was huge.

Dear sir, I am in your debt!

Thank you so much!



Lenny.





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to process multiple input xml files with a single xslt ? Divya XSLT 12 October 9th, 2018 03:01 AM
Transforming xml data using xslt nelly78 XSLT 2 September 16th, 2010 11:27 AM
Help needed transforming plist to XML by XSL Vartan XSLT 4 September 28th, 2007 03:11 PM
problem transforming XML using xslt micky3248 XSLT 7 August 18th, 2006 03:52 AM
Please help, xml transforming using xslt !!! daula7 XSLT 0 May 11th, 2006 01:29 PM





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