Solved

XSL Pass node-set to template

Posted on 2004-10-12
1
443 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

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

Suggested Solutions

The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
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…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

697 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