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 30th, 2005, 01:43 PM
Banned
 
Join Date: Jul 2005
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to compare nodes from 2 XML docs

My setup: XML > XSLT > CSS > ASP.NET/VB.NET (using tranformNode method)

My question: How can I compare node values (link & id) from 2 XML docs and display another node's value (url) as the result?

What I have so far:
XML doc (to be transformed - xmldoc1.xml):
Code:
<?xml version="1.0" encoding="UTF-8"?>
<external_links>
    <site id="site1">
        <title>Site #1</title>
        <description />
        <url>http://www.siteone.com</url>
        <target />
        <display />
    </site>
    <site id="site2">
        <title>Site #2</title>
        <description />
        <url>http://www.sitetwo.com</url>
        <target />
        <display />
    </site>
</external_links>
XML doc (to be included in XSLT stylesheet using document() method - xmldoc2.xml):
Code:
<pagetitle>
    <items>
        <item>
            <title>...</title>
            <address>...</address>
            <phone>...</phone>
            <email>...</email>
            <link>site1</link>
        </item>
        <item>
            <title>...</title>
            <address>...</address>
            <phone>...</phone>
            <email>...</email>
            <link>site2</link>
        </item>
    </items>
</pagetitle>
XSLT stylesheet (stylesheet.xsl):
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="UTF-8" indent="yes"/>
<xsl:variable name="external_links" select="document('external_links.xml')" />
    <xsl:template match="/">
        <xsl:for-each select="pagetitle/items/item">
            <xsl:if test="link != '' and link = $external_links/external_links/site/@id">
                <xsl:text>Website: </xsl:text>
                <a href="{$external_links/external_links/site/url}" target="_blank"><xsl:value-of select="$external_links/external_links/site/url" /></a>
            </xsl:if>
        </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>
Output:
Website: http://www.siteone.com
Website: http://www.siteone.com
Website: http://www.siteone.com
...

KWilliams





Similar Threads
Thread Thread Starter Forum Replies Last Post
Compare values in different nodes fann XSLT 9 September 11th, 2008 06:25 AM
XML + XSLT Compare Nodes tommyready XSLT 5 September 5th, 2007 03:18 AM
Merging 2 Xml docs nkuar XML 3 December 8th, 2005 05:22 AM
transformNode w/2 source XML docs? kwilliams XSLT 0 July 25th, 2005 03:38 PM
Handling remote XML docs in ASP delbarcr XML 1 March 25th, 2004 11:23 AM





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