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 10th, 2004, 03:05 PM
Authorized User
 
Join Date: Sep 2004
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default Beginner question on getting only certain elements

I have some XML that looks like this:

<ProgramMeta>
    <Title CrossAlign="No">Ancient Civilizations</Title>
    <PETOC>
        <PEMeta>
            <LabelInfo>
                <PEDiv1Label><Label><PreEnumLabel>Unit</PreEnumLabel></Label></PEDiv1Label>
                <PEDiv2Label><Label><PreEnumLabel>Chapter</PreEnumLabel></Label></PEDiv2Label>
                <PEDiv3Label><Label><PreEnumLabel>Lesson</PreEnumLabel></Label></PEDiv3Label>
            </LabelInfo>
            <AuthorList>
                <Author>Big Joe</Author>
            </AuthorList>
        </PEMeta>
        <PEFrontmatter BeginPage="1" EndPage="12" Enumeration="AlphaL" Type="Unnumbered" id="fm1">
            <PEDiv BeginPage="4" EndPage="12" Enumeration="AlphaL" Type="Unnumbered" id="fm2">
                <PETOCEntry id="fm2a">
                    <Title CrossAlign="No">State Standards</Title>
                </PETOCEntry>
            </PEDiv>
        </PEFrontmatter>
    </PETOC>

    <ProjectMeta>
        <Title CrossAlign="No">World History</Title>
        <SubTitle CrossAlign="No" HeadStyle="Block">A Triumph of Configuration</SubTitle>
    </ProjectMeta>

</ProgramMeta>

The output I want looks like this:

<header>
World History Ancient Civilizations

It's the ProgramMeta/ProjectMeta/Title followed by the ProgramMeta/Title. My stylesheet looks like this:

<xsl:template match="/">
&lt;header&gt;
<xsl:value-of select="ProgramMeta/ProjectMeta/Title" /> <xsl:value-of select="ProgramMeta/Title" />
</xsl:template>
</xsl:stylesheet>

But instead of just getting those two pieces of info and ignoring everything else, it's pulling in all the junk I don't want into an unformatted mess. How can I get just the pieces I want, without creating templates that do nothing for every single element I don't want (and there are a lot more - this is a stripped down sample).

I have no control over the XML; the DTD was signed off on long ago.

Thanks, and patience please for the newbie.


 
Old December 10th, 2004, 03:19 PM
Authorized User
 
Join Date: Nov 2004
Posts: 81
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to jkmyoung
Default

It should work. A couple possibilities?:
1. namespace (xmlns attribute) of the root element is different.
2. You have a <xsl:apply-templates/> somewhere.

Can't say more without seeing more.

 
Old December 10th, 2004, 03:31 PM
Authorized User
 
Join Date: Sep 2004
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default

No apply-templates anywhere. How could the namespace of the root element be different? The only namespace defined anywhere is in the xsl stylesheet tag. Here's the entire stylesheet:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" indent="no" />

<xsl:template match="/">
&lt;header&gt;
<xsl:value-of select="ProgramMeta/ProjectMeta/Title" /> <xsl:value-of select="ProgramMeta/Title" />
</xsl:template>
</xsl:stylesheet>

As far as the XML, most of what's stripped out is more of the same - more <Author> elements in the <AuthorList>, more <PEDiv> in <PEFrontmatter>, etc.


I even tried skipping the root node and going straight to ProgramMeta, like this:

<xsl:template match="ProgramMeta">
&lt;header&gt;
<xsl:value-of select="ProjectMeta/Title" /> <xsl:value-of select="Title" />
</xsl:template>
</xsl:stylesheet>

I get the same results:

<header>

    Ancient CivilizationsUnitChapterLessonBig JoeState StandardsEverything Is SwellThe BeginningUpon the CreationAnd Thence Becomes Unto ThatThe MiddleFeelin' Fine!What's The Rush?The EndDecrepitude EncroachesWhat Have We Learned?Don't Worry About ItFirst The Second PartOneTwoIn This SpotA Chipper ParakeetNobody Likes a LoserA Special FeatureA Very Special Feature of the FeatureA Catastrophic SuccessAncient Africapp. 140--211Ancient EgyptGeography: Civilizations developed in places that supported agriculture
or trade or both.Gift of the NileGeography: The Nile River helped Egypt develop a civilization.Economics: The fertile land provided everything Egyptians needed.Economics: The Nile and other resources influenced Egypt's
economy.Life in Ancient EgyptEconomics: Egyptians developed a complex society with many different
jobs and social roles.Science and Technology: Egyptians made advances in calendars, geometry,
medicine, and other areas.Belief Systems: Egyptians believed in many gods and a happy life
after death.The Pyramid BuildersGovernment: Egypt united under a central government that ruled
for centuries.Culture: Pharaoh Khufu built a huge monument to proclaim his glory.Government: Egypt entered a period of change as centralized rule
weakened.The New KingdomEconomics: Queen Hatshepsut ruled as pharaoh and expanded trade
during the New Kingdom.Belief Systems: Akhenaton tried to change Egyptian religion by
replacing the old gods with one god called Aton.Government: Ramses II ruled Egypt for decades and created a stable
empire.The Kush CivilizationCulture: Ways of living change as humans interact with each other.Nubia and the Land of KushGeography: The region of Nubia had connections with Egypt.Government: A powerful king of Kush conquered Egypt and ruled as
pharaoh. Economics: Mero was an important economic center linking
Egypt and the interior of Africa.The Kingdom of AksumGovernment: A new power, Aksum, rises south of Egypt.Culture: Ezana expands Aksum's power and converts to Christianity.Culture: Aksum's cultural and technical achievements were
long lasting.Western, Central, and Southern AfricaGeography: The people of west, central, and south Africa adapted
to life in a variety of environments.Economics: The Nok people were the first iron workers of west Africa.Geography: Migration by the Bantu people from west Africa populated
central and south Africa. World HistoryA Triumph of Configuration, , , , , , , ,
 
Old December 10th, 2004, 03:51 PM
Authorized User
 
Join Date: Nov 2004
Posts: 81
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to jkmyoung
Default

odd, but think I've seen this before with certain processors; try adding a template afterwards
<xsl:template match="*"/>

 
Old December 10th, 2004, 04:37 PM
Authorized User
 
Join Date: Sep 2004
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Nope, still gives the mess.

 
Old December 10th, 2004, 04:38 PM
Authorized User
 
Join Date: Sep 2004
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default

DOH! Just remembered that I resaved the xsl under a different name when I made some changes, but was still running the transform with the old file name. Added the template match="*", ran the *correct* transform, and it worked! Thanks for your help.






Similar Threads
Thread Thread Starter Forum Replies Last Post
xslt beginner question cfflexguy XSLT 4 October 16th, 2007 09:11 AM
beginner C++ question p62 proslambano BOOK: Ivor Horton's Beginning Visual C++ 2005 4 February 7th, 2007 04:23 PM
Beginner Question dkr72 Excel VBA 1 January 18th, 2005 09:37 AM
beginner question saudyonline General .NET 2 September 21st, 2004 01:56 AM
total beginner question kevin777 C++ Programming 5 November 3rd, 2003 11:00 PM





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