Solved

XSL Pass node-set to template

Posted on 2004-10-12
1
441 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Conditional Formatting 4 41
Parse data from XMLtype data in Oracle SQL 5 80
XSL - change date format 3 45
How can I assign SimpleXMLElements to variables? 5 64
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

773 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