logo       

Re: replacing a node in in-memory XML: msg#00013

Subject: Re: replacing a node in in-memory XML
Maybe there's not a lot of difference in the two examples given - but I guess my preference will always be for a non-XML syntax for my code if I have a choice.

John

Andrew Welch wrote:
Doesn't the OP want to set service/@value to true that matches the input?

If so the XSLT could be the "identity template + plus specific
template" pattern:

<xsl:template match="@*|node()">
  <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
  </xsl:copy>
</xsl:template>

<xsl:template match="services">
  <services>
    <service value="{service = 1}">1</service>
    <service value="{service = 2}">2</service>
    <service value="{service = 3}">3</service>
  </services>
</template>

which i think is quite nice and easy to read too, once you get the way
apply-templates works.  It's also very easy to add further specific
templates, and of course its open to be overridden by a stylesheet
that imports it.


On 06/11/2007, John Snelson 
<john.snelson-QHcLZuEGTsvQT0dZR+AlfA@xxxxxxxxxxxxxxxx> wrote:
Hi Wolfgang,

In the absence of XQuery Update, I really like your technique for doing
this transformation. I think it's actually simpler and easier to read
than the equivalent XSLT.

John

Wolfgang Meier wrote:
Hi Robert,

I am trying to figure out the best way to replace a node within an in-memory
XML fragment.
I really like to use the typeswitch statement for things like this:

declare function t:replace($node as node()) as node() {
    typeswitch ($node)
        case $elem as element(services) return
            <services>
                <service value="false">1</service>
                <service value="true">2</service>
                <service value="false">3</service>
            </services>
        case $elem as element() return
           element { node-name($elem) } {
                $elem/@*, for $child in $elem/node() return t:replace($child)
            }
        default return $node
};

t:replace(doc("test.xml")/*)

Wolfgang
_______________________________________________
talk-9zRdbLeNGsRBDgjK7y7TUQ@xxxxxxxxxxxxxxxx
http://x-query.com/mailman/listinfo/talk

--
John Snelson, Oracle Corporation
Berkeley DB XML:        http://www.oracle.com/database/berkeley-db/xml
XQilla:                                  http://xqilla.sourceforge.net
_______________________________________________
talk-9zRdbLeNGsRBDgjK7y7TUQ@xxxxxxxxxxxxxxxx
http://x-query.com/mailman/listinfo/talk





--
John Snelson, Oracle Corporation
Berkeley DB XML:        http://www.oracle.com/database/berkeley-db/xml
XQilla:                                  http://xqilla.sourceforge.net


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
python.cheetah/...    linux.altlinux....    qnx.openqnx.dev...    horde.cvs/2002-...    os.openbsd.misc...    web.zope.cvs/20...    fsf.proofreader...    emulators.wine....    kde.promotion/2...    yellowdog.gener...    creativecommons...    user-groups.lin...    xfree86.fonts/2...    ietf.ips/2006-1...    jakarta.velocit...    redhat.fedora.c...    text.xml.cocoon...    security.ossim....    games.mud.devel...    bacula.user/200...    video.videodb.d...    netbsd.devel.ww...    apache.webservi...    db.mysql.c++/20...    music.equipment...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe