[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: apply one template to another

Subject: Re: apply one template to another
From: Robert Koberg <rob@xxxxxxxxxx>
Date: Wed, 01 Nov 2006 08:17:39 -0500
xforms copy
Adam Retter wrote:
I am using a copy pattern that Michael Kay very kindly described
originally for me.
These are the last two templates in my document that do the copying-

<xsl:template match="*" mode="copy">
        <xsl:copy>
            <xsl:copy-of select="@*"/>
            <xsl:apply-templates mode="copy"/>
        </xsl:copy>
</xsl:template>
<xsl:template match="/root/xform">
        <xsl:apply-templates mode="copy"/>
</xsl:template>


Do you need the identity template to be in a mode. In other words, could you take out the mode and have it be the default. That way you could apply templates here:
...
<xsl:choose>
<xsl:when test="empty(/root/page)">
<xsl:apply-templates"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="/root/page"/>
</xsl:otherwise>
</xsl:choose>
...
and just match the page elem (or anything else) to override the default copy behavior.


best,
-Rob






Now I have a template that makes a conditional copy of the
/root/xform/xforms:model/xforms:instance node -

    <xsl:template match="/root/xform/xforms:model/xforms:instance"
mode="copy">
        <xforms:instance>
            <xsl:copy-of select="@*"/>
            <xsl:choose>
                <xsl:when test="empty(/root/page)">
                    <xsl:copy-of select="child::node()"/>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:copy-of select="/root/page"/>
                </xsl:otherwise>
            </xsl:choose>
        </xforms:instance>
    </xsl:template>


Now, what I would like to do is apply a template to that template, so that I can conditionally replace the /root/xform/xforms:model/xforms:instance/page/contact node with a custom node. I tried something like this but I couldnt get it to work, I also tried playing with priorities and modes but didnt make any progress.

<xsl:template
match="/root/xform/xforms:model/xforms:instance/page/contact"
mode="copy">
<xsl:choose>
<xsl:when test="empty(/root/contact)">
<xsl:copy-of select="."/>
</xsl:when> <xsl:otherwise>
<xsl:copy-of select="/root/contact"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>



If you could provide me with details of how to acheive that, I think I could extend that to other nodes that I want to conditinally replace with custom nodes -

/root/xform/xforms:model/xforms:instance/page/location
/root/xform/xforms:model/xforms:instance/page//start
/root/xform/xforms:model/xforms:instance/page//end

Thanks very much - Adam Retter


For reference my XML document structure looks something like this -


<root>
    <contact>
        <title>Miss</title>
        <firstname>Jo</firstname>
        <lastname>Smith</lastname>
        <telephone>
            <number type="Office">01404 812345</number>
        </telephone>
        </contact>
    <location>
        <address>The Old Institute</address>
        <address>Yonder Street</address>
        <town>Ottery St Mary</town>
        <county>Devon</county>
        <postcode>EX11 1XX</postcode>
    </location>
    <start>2006-11-01T09:00:00.00</start>
    <end>2006-11-01T18:00:00.00</end>
    <xform xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:xforms
        ="http://www.w3.org/2002/xforms">
        <xforms:model ev:event="xforms-revalidate"
ev:defaultAction="cancel">
            <xforms:submission id="submit"
action="http://localhost:8080/exist/servlet/db/CommunityDirectory/index.
xql?action=savepage" method="post" replace="all"/>
            <xforms:instance>
                <page design="event">
                    <title/>
                    <description/>
                    <when>
                        <start/>
                        <end/>
                        <occurs>Once</occurs>
                    </when>
                    <contact>
                        <title/>
                        <firstname/>
                        <lastname/>
                        <telephone/>
                    </contact>
                    <location>
                        <address/>
                        <town/>
                        <county/>
                        <postcode/>
                        <directions/>
                    </location>
                    <cost/>
                </page>
            </xforms:instance>
      </xforms:model>
   </xform>
</root>

Adam Retter

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2007 All Rights Reserved.