Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: [xsl] apply one template to another

From: Robert Koberg <rob@---------->
To:
Date: 11/1/2006 1:18:00 PM
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


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent