Solved

XSL Pass node-set to template

Posted on 2004-10-12
1
439 Views
Last Modified: 2011-11-09
WinXP, MSXML 4/.NET.

The basic goal is to pass a node set to a template (see below)
<?xml version="1.0" encoding="utf-8" ?>
<flights>
      <flight number="101" line="AQ" time="2004-05-17T11:12:00" type="A">
            <values field="gate">B12</values>
      </flight>
      <flight number="102" line="AQ" time="2004-05-17T12:12:00" type="D">
            <values field="gate">B12</values>
      </flight>
            <flight number="103" line="AQ" time="2004-05-17T13:12:00" type="A">
            <values field="gate">B12</values>
      </flight>
            <flight number="104" line="AQ" time="2004-05-17T14:12:00" type="D">
            <values field="gate">B12</values>
      </flight>
</flights>

--------------------------------------------------------------------------------------
Within 1 hour from now: (select only top 1 arrival/departure (type=A/D)where gate='B12')

If there are NO Arriving/Departing
      display "No Flights"
      
If Only Arriving
      Display "Flight (line + number) is Arriving..."
      
If Departing & Arriving
      Display "Flight (line + number) is Departing ..Flight (line + number) is Arriving"
                  
============================================================
What I'd like to do is use a departure template with an arrival node-set as a parameter.
Then when processing the departure node, use a template for the arrival processing. I *think* the msxsl:node-set function is what I need, but can't find the right answer on the web.

I have simplified both the XML and logic. There is a lot more going on in the
data selection and the presentation logic, but this should do.

0
Comment
Question by:lrr81765
1 Comment
 
LVL 7

Accepted Solution

by:
J_Mak earned 500 total points
ID: 12294359
A node-set parameter is basically a parameter which references more than one node. You can pass node-sets to templates using axes such as:

- ancestor
- ancestor-or-self
- attribute
- child
- descendant
- descendant-or-self
- following
- following-sibling
- namespace
- parent
- preceding
- preceding-sibling
- self

For example, you could something like this (it may not be what you want but it will use pass a node-set parameter to a template):

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <!-- assuming you want to output an XML file -->
    <xsl:output method="xml"/>
    <xsl:template match="/">
        <xsl:apply-templates select="flights"/>
    </xsl:template>
    <xsl:template match="flights">
        <xsl:call-template name="ProcessChildren">
            <xsl:with-param name="Node_Set" select="./child::*"/>
        </xsl:call-template>
    </xsl:template>
    <xsl:template name="ProcessChildren">
        <xsl:param name="Node_Set"/>
        <xsl:value-of select="count($Node_Set[@type='A'])"/>
    </xsl:template>
</xsl:stylesheet>

The above example that I have given you, will pass a node set, which contains all the children of the 'flights' element. The template then counts how many 'flight' children have the type attribute having the value of 'A'. The answer should be 2.

For more details on the above axes, have a look at this link:

http://www.zvon.org/xxl/XSLTreference/Output/axesIndex.html

Hope that helps!
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Automatically Generate Documents from XML database 10 46
Issue exporting to XML with Excel 2016 3 79
Word files to Wordpress Posts 2 43
Transform XML to Excel using XSL 1 23
The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now