[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
At 2007-11-30 22:13 +0000, Mark Anderson wrote:
It is called "the identity template" and looks like this:
In that template, the priority of both matches is negative 1.
Matches such as match="a" have a priority of zero, so are higher. When you add more to this, the priority is .5 (more nuanced with XSLT 2.0), so is higher still.
This is a very common pattern and I have the template as part of my unedited raw stylesheet that I use to start new stylesheets.
I hope this helps.
. . . . . . . . . Ken
Re: [xsl] Dumb Question - XML to XML changing only a few values
Subject: Re: [xsl] Dumb Question - XML to XML changing only a few values From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Fri, 30 Nov 2007 17:28:58 -0500 |
At 2007-11-30 22:13 +0000, Mark Anderson wrote:
Is there a way to say "just copy everything to the destination XML, but any instance of <a></a> will have its contents replaced"?
It is called "the identity template" and looks like this:
<xsl:template match="@*|node()"><!--identity for all other nodes--> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template>
In that template, the priority of both matches is negative 1.
Matches such as match="a" have a priority of zero, so are higher. When you add more to this, the priority is .5 (more nuanced with XSLT 2.0), so is higher still.
For example
Source XML
...
So I just want to say replace contents of <a></a> with 12345 and just copy everything else
Destination XML ...
This is a very common pattern and I have the template as part of my unedited raw stylesheet that I use to start new stylesheets.
I hope this helps.
. . . . . . . . . Ken
T:\ftemp>type mark.xml <test> <a>A</a> <b>B</b> <c>C</c> <d>D</d> <e>E</e> <f>F</f> <g>G</g> </test> T:\ftemp>type mark.xsl <?xml version="1.0" encoding="US-ASCII"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="a"> <xsl:copy>12345</xsl:copy> </xsl:template>
<xsl:template match="@*|node()"><!--identity for all other nodes--> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template>
</xsl:stylesheet> T:\ftemp>xslt mark.xml mark.xsl con <?xml version="1.0" encoding="utf-8"?><test> <a>12345</a> <b>B</b> <c>C</c> <d>D</d> <e>E</e> <f>F</f> <g>G</g> </test> T:\ftemp>
-- Comprehensive in-depth XSLT2/XSL-FO1.1 classes: Austin TX,Jan-2008 World-wide corporate, govt. & user group XML, XSL and UBL training RSS feeds: publicly-available developer resources and training G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (F:-0995) Male Cancer Awareness Nov'07 http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Dumb Question - XML to XML ch, Mark Anderson | Thread | [xsl] CDATA and Named Entities to A, Mark Anderson |
RE: [xsl] Help with tree menu, Lucas Gonçalves Gros | Date | [xsl] CDATA and Named Entities to A, Mark Anderson |
Month |