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 January 7th, 2008, 05:15 AM
Authorized User
 
Join Date: Nov 2007
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to control Styles in Multiple Xsl

Hii..

I am trying to transform xml files through xslt. I am having an element <people> in two xml files. I have linked all xml files in one xml file and import all xsl files in one xsl file.

XML1:

<people><head>People</head>
<list><listitem><p>Paleo-Indians</p></listitem>
<listitem><p>Archaic Indians</p></listitem></list></people>

XSL1:

<xsl:template match="lesson/opener/people">
<xsl:element name="sidebar">
<xsl:attribute name="render">required</xsl:attribute>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>

XML2

<people> is the root node for this xml.

XSL2:

<xsl:template match="people">
<level><xsl:attribute name="class">People</xsl:attribute><xsl:apply-templates/></level>
</xsl:template>



The output is: (The style which i have given in the xsl2 is applied to xml1)

<level class="People"><hd>People</hd>
<list><li><p>Paleo-Indians</p></li>
<li><p>Archaic Indians</p></li></list></level>

Thanks in Advance,
srkumar
 
Old January 7th, 2008, 05:37 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You've said what you did and what happens, you haven't really said what you wanted or expected to happen. So I'm guessing: perhaps you wanted the template rule in XSL1 to be applied to the <people> element in XML1, and the rule in XSL2 to be applied to the <people> element in XML2?

This would happen automatically if XSL1 and XSL2 have the same import precedence, or of XSL1 has higher import precedence. So it all depends on how you arranged the xsl:import declarations, which you haven't shown us. Perhaps you did

<xsl:import href="xsl1"/>
<xsl:import href="xsl2"/>

This would give XSL2 higher precedence which would account for the behaviour you are seeing.

You could fix this by changing the import order, or by changing the template rule in XSL2 so it only matches a <people> element at the outermost level: match="/people".



Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old January 7th, 2008, 07:12 AM
Authorized User
 
Join Date: Nov 2007
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ya its working...

Thanks Mh...

 
Old January 7th, 2008, 08:00 AM
Authorized User
 
Join Date: Nov 2007
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It again problem mhkay...

when i gave /people in my XSL2, The element <level> is not converted.

XSL2:

<xsl:template match="/people">
<level><xsl:attribute name="class">People</xsl:attribute><xsl:apply-templates/></level>
</xsl:template>

XML1:
:-Also the attribute not converted in XML1.
<sidebar render="required">
<hd>People</hd>
<list><li><p>Paleo-Indians</p></li>
<li><p>Archaic Indians</p></li></list></sidebar>

XSL1:

<xsl:template match="lesson/opener/people">
<xsl:element name="sidebar">
<xsl:attribute name="render">required</xsl:attribute>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>

<xsl:template match="lesson/opener/people/list">
<xsl:element name="list">
<xsl:attribute name="type">pl</xsl:attribute>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>


Please Advice...
 
Old January 7th, 2008, 08:43 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Please show your complete stylesheet.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old January 8th, 2008, 12:07 AM
Authorized User
 
Join Date: Nov 2007
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hii Mhkay...

Sorry i am in big confusion Thats y i am disturbing u....

Here is my entire process..

Main.xml

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE Catalog [
<!ENTITY SXEIN10ASE4X_U2L1 SYSTEM "SXEIN10ASE4X_U2L1.xml">
<!ENTITY SXEIN10ASE4X_U2PE SYSTEM "SXEIN10ASE4X_U2PE.xml">
]>
<Catalog>
&SXEIN10ASE4X_U2L1;
&SXEIN10ASE4X_U2PE;
</Catalog>

Main.xsl

<?xml version="1.0" encoding='UTF-8'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:import href="lesson.xsl"/>
<xsl:import href="people.xsl"/>
<xsl:output method="xml" omit-xml-declaration="no" indent="yes" encoding="UTF-8" doctype-system="dtbook-2005-2.dtd"/>
<xsl:strip-space elements="*"/>
<xsl:template match="Catalog">
<dtbook><head/><book><bodymatter><xsl:apply-templates/></bodymatter></book></dtbook>
</xsl:template>
</xsl:stylesheet>


XML1:

<?xml version="1.0" encoding="utf-8"?>
<lesson unit="2"><num>Lesson</num>
<title>Early People of Indiana</title>
<opener>
<people><head>People</head>
<list><listitem><p>Paleo-Indians</p></listitem>
<listitem><p>Archaic Indians</p></listitem></list></people></opener></lesson>

XSL1:

<?xml version="1.0" encoding='UTF-8'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" omit-xml-declaration="no" indent="yes" encoding="UTF-8" doctype-system="dtbook-2005-2.dtd"/>

<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>

<xsl:template match="lesson/opener//list">
<xsl:element name="list">
<xsl:attribute name="type">pl</xsl:attribute>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>

<xsl:template match="lesson">
<level><xsl:attribute name="class">lesson</xsl:attribute><xsl:apply-templates/></level>
</xsl:template>

</xsl:stylesheet>

XML2:

<?xml version="1.0" encoding="utf-8"?>
<people unit="2">
<list role="bull">
<title>Miami people</title>
<listitem><head>#x2022;</head><p>Farmed and hunted animals</p></listitem></list></people>

XSL2:

<xsl:template match="/people">
<level><xsl:attribute name="class">People</xsl:attribute><xsl:apply-templates/></level>
</xsl:template>

Please Advice...

srkumar
 
Old January 8th, 2008, 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

The way you appear to be importing the two XML files the <people> element is not the root of the document. Therefore "/people" will not match anything. Change this so it matches the position of the people element you want to provide the template for, e.g. "Catalog/people" or "people[not(parent::opener)]".

/- Sam Judson : Wrox Technical Editor -/
 
Old January 8th, 2008, 07:22 AM
Authorized User
 
Join Date: Nov 2007
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default


Thanks Sam.. Its working...

 
Old January 9th, 2008, 05:25 AM
Authorized User
 
Join Date: Nov 2007
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry mhkay, Again i am having a doubt..

I want to remove the DOCTYPE declaration from the xml file.. There are two DOCTYPE declaration in my xml file...

1. In the separate XML file

<!DOCTYPE biography SYSTEM "sample.dtd">
<biography unit="2"><title>George Rogers Clark</title></biography>

2. In the Main XML file where i have given link to all my xml files.

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE Catalog [
<!ENTITY biography SYSTEM "biography.xml">
]>
<Catalog>
&biography;
</Catalog>

So, i have to remove the DOCTYPE declaration in the separate files manually.

Please Advice,

srkumar
 
Old January 9th, 2008, 04:25 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You're trying to combine the two XML files by treating them as "external general parsed entities". But an XML file can't be used as an external general parsed entity if it contains a DOCTYPE declaration.

The usual way to tackle this problem would be to read both XML files separately from the stylesheet using the document() function, rather than trying to combine them into a single file.

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
XSL multiple files in table (nested for-each ?) pedoublety XSLT 5 August 21st, 2007 08:00 AM
Multiple xsl styles applied to central xml doc patgibbs1 XSLT 1 March 20th, 2006 11:52 AM
Pass multiple values to XSL? myhtpc XSLT 5 March 17th, 2006 11:16 AM
Grouping multiple paragraph styles under 1 parent ROCXY XML 0 January 4th, 2006 09:42 AM
Multiple Tables Display in XSL bmagadi XSLT 1 February 8th, 2005 03:06 PM





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