Solved

XSL Pass node-set to template

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

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

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

Suggested Solutions

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.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

831 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