Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 21st, 2007, 07:56 AM
Registered User
 
Join Date: May 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default question on xslt templates -- urgent


Given below is the xml and xsl code snippet for my web page.
I have used two templates one for filling Medium drop down and another for Priority drop down.

My question is ...

    the template match="Priority/PriorityList" --does this execute for both request call and response call??

If it executes...for both ...is there any way to write one generic template which serves for all of the 4 template calls??



XML CODE SNIPPET:
----------------
<Report>
  <CasePacketRequest>
    <ReqPriority></ReqPriority>
    <Priority>
        <PriorityList value="E">Expedited</PriorityList>
        <PriorityList value="S">Standard</PriorityList>
    </Priority>
    <ReqMedium></ReqMedium>
    <Medium>
        <MediumList value="F">Fax</MediumList>
        <MediumList value="M">Mail</MediumList>
    </Medium>
  </CasePacketRequest>
  <CasePacketResponse>
    <ResPriority></ResPriority>
    <Priority>
        <PriorityList value="E">Expedited</PriorityList>
        <PriorityList value="S">Standard</PriorityList>
    </Priority>
    <ResMedium></ResMedium>
    <Medium>
        <MediumList value="F">Fax</MediumList>
        <MediumList value="M">Mail</MediumList>
    </Medium>
  </CasePacketResponse>
</Report>


XSL CODE SNIPPET:
----------------
<select name="selectPriority" class="bodytext" onChange="changeOption(selectedIndex)">
    <xsl:apply-templates select="CasePacketRequest/Priority/PriorityList"/>
</select>

<select name="selectMedium" class="bodytext" onChange="changeOption(selectedIndex)">
    <option value="">--- Select ---</option>
    <xsl:apply-templates select="CasePacketRequest/Medium/MediumList"/>
</select>

<select name="selectPriority" class="bodytext" onChange="changeOption(selectedIndex)">
    <xsl:apply-templates select="CasePacketResponse/Priority/PriorityList"/>
</select>

<select name="selectMedium" class="bodytext" onChange="changeOption(selectedIndex)">
    <option value="">--- Select ---</option>
    <xsl:apply-templates select="CasePacketResponse/Medium/MediumList"/>
</select>


<xsl:template match="Priority/PriorityList">
    <option><xsl:attribute name="value"><xsl:value-of select="@value"/>
            </xsl:attribute>
            <xsl:if test="../ReqPriority=@value">
                <xsl:attribute name="selected" />
            </xsl:if>
            <xsl:value-of select="."/>
    </option>
</xsl:template >

<xsl:template match="Medium/MediumList">
    <option><xsl:attribute name="value"><xsl:value-of select="@value"/>
            </xsl:attribute>
            <xsl:if test="../ReqMedium=@value">
                <xsl:attribute name="selected" />
             </xsl:if>
            <xsl:value-of select="."/>
    </option>
</xsl:template >

 
Old May 21st, 2007, 05:17 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

The template match="Priority/PriorityList" matches all four of your PriorityList elements. It will be invoked to process them provided that (a) the elements are selected for processing in an xsl:apply-templates call, and (b) there is no higher-priority template rule that matches those elements.

I'm not sure what you mean by the second part of your question. It might help to show your current code and explain whether or not it does what you expect.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
C++ templates in XSLT paulo2005 XSLT 1 July 5th, 2007 04:27 PM
simple XSLT apply-templates question fannus XSLT 7 March 27th, 2007 02:11 AM
XSLT HELP URGENT! pkg XSLT 3 June 22nd, 2005 01:46 AM
making changes to templates. Need help urgent kirangnvs BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 0 June 13th, 2005 04:24 PM
XSLT Templates bmains XSLT 2 December 16th, 2003 02:36 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.