This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Is it possible to merge attributes from multiple elements?
- To: xsl-list at mulberrytech dot com
- Subject: Re: Is it possible to merge attributes from multiple elements?
- From: Edwin Glaser <edwin at pannenleiter dot de>
- Date: Sun, 18 Jun 2000 12:30:06 +0200
- References: <200006180529.WAA23043@desmo.lee-turk.com>
- Reply-To: xsl-list at mulberrytech dot com
You wrote:
> I'm trying to write a template that combines attributes from two elements into a
> single element. The goal is to use XSLT to translate something like this:
>
> <matrix>
> <column c="1">
> <column c="2">
> <row r="1">
> <row r="2">
> </matrix>
>
> into something like this:
>
> <table>
> <tr><td c="1" r="1"/><td c="2" r="1"/></tr>
> <tr><td c="1" r="2"/><td c="2" r="2"/></tr>
> </table>
> As far as I've been able to tell, variables, can't hold anything other than simple
> text--much less a collection of attribute nodes.
Don't know if it is possible with pure xslt, but with a rtf->nodeset converter
your solution needs only slightly modifications. Here is a xalan example, saxon
has a builtin converter. Let's hope the next xslt specification will remove those
brain-dead limitations!
<?xml version="1.0" encoding="ISO-8859-1" ?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:util="de.pannenleiter.xmlapache.Util"
exclude-result-prefixes="util">
<xsl:template match="row">
<xsl:variable name="this"><xsl:copy-of select="."/></xsl:variable>
<tr>
<xsl:for-each select="../column">
<td>
<xsl:for-each select="@*">
<xsl:copy/>
</xsl:for-each>
<xsl:for-each select="util:nodeset($this)/*/@*">
<xsl:copy/>
</xsl:for-each>
</td>
</xsl:for-each>
</tr>
</xsl:template>
</xsl:stylesheet>
public class Util
{
public static XNodeSet nodeset(Node value)
throws Exception
{
Node node = (Node) value;
return new XNodeSet((Node) value);
}
}
Hope it helps, edwin
--
Edwin Glaser -- edwin@pannenleiter.de
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list