Solved

XSL Pass node-set to template

Posted on 2004-10-12
1
435 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
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
XSL Grouping 7 36
D3, mouseover, SVG, Javacript 6 76
Help with SimpleXML charts with PHP 4 63
XML Data Missing in PHP SimpleXML 8 20
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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

772 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

12 Experts available now in Live!

Get 1:1 Help Now