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

RE: Identify node with variable and replace its value

Subject: RE: Identify node with variable and replace its value / mode problem
From: "Lars Huttar" <lars_huttar@xxxxxxx>
Date: Fri, 9 Jan 2004 12:20:34 -0600
xslt replace node value
Andreas,
You have some <xsl:apply-templates> statements that are
located outside of any template. This is not a valid XSL
stylesheet. If the stylesheet is being executed anyway,
I suspect those <xsl:apply-templates> statements are being ignored.
(That would be consistent with your comments about what each
version does.)
You would probably benefit from reading a tutorial about
the stylesheet processing model -- how and when the
processor applies templates.

As for your current task, if I understand what it is
you want to do, here's an approach:


<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:param name="id" select="'1'" />
    
    <!-- identity transform -->
    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()" />
        </xsl:copy>
    </xsl:template>
    
    <!-- process certain <title> elements specially -->
    <xsl:template match="/newspage/news/title">
        <xsl:choose>
            <xsl:when test="parent::news/@id = $id">
                process specially...
            </xsl:when>
            <xsl:otherwise>
                <xsl:copy>
                    <xsl:apply-templates select="@*|node()" />
                </xsl:copy>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
</xsl:stylesheet>


> Hi there,
> 
> I want to replace certain node values in elements that are 
> identified by 
> an id passed as an parameter. I know I can not use a variable in a 
> match, so I try to use apply-templates with select and mode.
> The pattern seems to be ok, the first example is doing well 
> except I can 
> not pass a variable.
> Using an apply-templates replaces ALL titles - and using 
> apply-templates 
> with a mode just copies the file...
> Any ideas? Your help is appreciated.
> 
> This is working, but I can't pass the parameter:
> 
> <xsl:template match="node()|@*">
>  <xsl:copy>
>    <xsl:apply-templates select="@*|node()" />
>  </xsl:copy>
> </xsl:template>
> 
> 
> <xsl:template match="/newspage/news[@id='1']/title">
> <title>replace title</title>
> </xsl:template>
> 
> 
> This is supposed to work, but it replaces ALL titles...
> 
> <xsl:template match="node()|@*">
>  <xsl:copy>
>    <xsl:apply-templates select="@*|node()" />
>  </xsl:copy>
> </xsl:template>
> 
> 
> <xsl:apply-templates select="/newspage/news[@id='1']/title"/>
> 
> <xsl:template match="title">
> <title>replace title</title>
> </xsl:template>
> 
> 
> Just copies file:
> 
> <xsl:template match="node()|@*">
>  <xsl:copy>
>    <xsl:apply-templates select="@*|node()" />
>  </xsl:copy>
> </xsl:template>
> 
> 
> <xsl:apply-templates select="/newspage/news[@id='1']/title" 
> mode="replace" />
> 
> <xsl:template match="title" mode="replace">
> <title>replace title</title>
> </xsl:template>
> 
> P.S. Sorry, made a mistake when posting this message last 
> night to an other thread.
> 
> 
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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-2013 All Rights Reserved.