This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Is it possible to merge attributes from multiple elements?


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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]