xsl-list
[Top] [All Lists]

Re: Problem with nested Stuff

2005-11-14 13:19:11
If all you want is to replace the contents of any element that has a myid 
attribute with the value of the myid attribute, you can do it with two 
templates: an identity transform and another template that matches any 
element with a myid attribute. Here's a stylesheet that does it:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

  <xsl:output method="xml" version="1.0" omit-xml-declaration="no" 
indent="yes"/>

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

  <xsl:template match="*[(_at_)myid]">
    <xsl:copy>{<xsl:value-of select="@myid"/>}</xsl:copy>
  </xsl:template>

</xsl:stylesheet>

I tested it with Xalan Java 2.4.1 (after I added a root element to your 
XML snippet).

The difference between my approach and Jon Gorman's approach is that I use 
templates and he uses xsl:choose, but the approaches are otherwise very 
similar. (Jon's response came in as I was writing my response, by the 
way.)

I suspect you may want something more than what Jon and I have shown, 
though, as it seems odd to me that you would want to throw away the 
content of elements that have myid attributes.

Jay Bryant
Bryant Communication Services
(presently consulting at Synergistic Solution Technologies)



"Miladen Jolie" <my(_dot_)office(_at_)gmx(_dot_)de> 
11/14/2005 01:20 PM
Please respond to
xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com


To
xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
cc

Subject
[xsl] Problem with nested Stuff






Hi,

i want to get from:

<div myid="test">blah</div>
<table>
  <tr>
    <td>test</td>
    <td myid="test2">blah2</td>
  </tr>
</table>

this:

<div>{test}</div>
<table>
  <tr>
    <td>test</td>
    <td>{test2}</td>
  </tr>
</table>

How can achieve this?

Thx in advance.

Miller

-- 
Highspeed-Freiheit. Bei GMX supergünstig, z.B. GMX DSL_Cityflat,
DSL-Flatrate für nur 4,99 Euro/Monat*  http://www.gmx.net/de/go/dsl

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--




--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>