[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Is it possible to merge attributes from multiple element
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@xxxxxxxxxxxxxxx XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|