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 September 13th, 2005, 04:14 PM
Registered User
 
Join Date: Sep 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default xsl matching with single file

I am trying to search and match information across an xml document.

1.)team.xml

<teams>
    <team-members>
        <team>
            <team-name>FirstTeam</team-name>
            <mascot>2ColumnLayout</mascot>
            <player>Bob</player>
            <player>Jeff</player>
        </team>
    </team-members>

    <players>
        <player>
            <position>First</position>
            <info>
                <number>22</number>
                <player-name>Bob</player-name>
                <weight>175</weight>
                <height>60</height>
            </info>
            <title>Bob on First</title>
        </player>
        <player>
            <position>Second</position>
            <info>
                <number>33</number>
                <player-name>Jeff</player-name>
                <weight>150</weight>
                <height>58</height>
            </info>
            <title>Jeff on Second</title>
        </player>
    </players>
</teams>

2. desired-team.xml
<teams>
    <team>
        <teamname>FirstTeam</teamname>
        <player>
            <name>Bob</name>
            <number>22</number>
            <weight>175</weight>
            <height>60</height>
            <title>Bob on First</title>
        </player>
        <player>
            <name>Jeff</name>
            <number>33</number>
            <weight>150</weight>
            <height>58</height>
            <title>Jeff on Second</title>
        </player>
    </team>
</teams>

Any help would be great.
Thanks
Kevin Nilson
http://www.javaclimber.com

 
Old September 13th, 2005, 06:27 PM
Registered User
 
Join Date: Sep 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here is the xsl that I am trying to finish:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" version="1.0">
    <xsl:output method="xml"/>
    <xsl:template match="/">
        <teams>
            <xsl:apply-templates select="/teams/team-members/team"/>
        </teams>
    </xsl:template>

        <xsl:template match="team">
        <team>
            <teamname><xsl:value-of select="team-name"/></teamname>
            <xsl:apply-templates select="player"/>
        </team>
    </xsl:template>

    <xsl:template match="player">
        <player>
            <xsl:variable name="player-name" select="." />
            <name><xsl:value-of select="$player-name"/></name>
            <number>DON'T KNOW WHAT TO PUT HERE</number>
            <weight>DON'T KNOW WHAT TO PUT HERE</weight>
            <height>DON'T KNOW WHAT TO PUT HERE</height>
        </player>
    </xsl:template>
</xsl:stylesheet>

Thanks
Kevin Nilson
http://www.javaclimber.com

 
Old September 14th, 2005, 12:16 AM
Registered User
 
Join Date: Sep 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I figured it out:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" version="1.0">
    <xsl:output method="xml"/>
    <xsl:template match="/">
        <teams>
            <xsl:apply-templates select="/teams/team-members/team"/>
        </teams>
    </xsl:template>

    <xsl:template match="team">
        <team>
            <teamname>
                <xsl:value-of select="team-name"/>
            </teamname>
            <xsl:apply-templates select="player"/>
        </team>
    </xsl:template>

    <xsl:template match="player">
        <player>
            <xsl:variable name="player-name" select="."/>
            <name>
                <xsl:value-of select="$player-name"/>
            </name>

            <xsl:for-each select="/teams/players/player/info/player-name">
                <xsl:if test="current()=$player-name">
                    <xsl:value-of select="."/>
                    <number>
                        <xsl:value-of select="../number"/>
                    </number>
                    <weight>
                        <xsl:value-of select="../weight"/>
                    </weight>
                    <height>
                        <xsl:value-of select="../height"/>
                    </height>
                </xsl:if>
            </xsl:for-each>
        </player>
    </xsl:template>
</xsl:stylesheet>






Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple FOP files to single PDF using XSL bhavanimachani XML 7 March 28th, 2008 05:59 AM
Using XSL to generate single pdf doc bhavanimachani XML 2 March 24th, 2008 11:57 PM
how to restore single file group Sameer SQL Server 2000 1 September 29th, 2004 11:25 PM
Multiple file input single file output.... jdm_mboy Biztalk 1 July 2nd, 2003 03:35 AM
XSL Transform with xsl string NOT xsl file skin XSLT 0 June 16th, 2003 07:30 AM





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