Q:

Using XPath in XSL to select all attribute values of a node with attribute name starting with a given string

I have some xml which looks like this:
<row>
    <anode myattr1="value1" anotherAttr="notthis">
        blah
    </anode>
    <anothernode myattr1="value1" myattr2="value2" anotherAttr="notthis">
        blahBlah
    </anothernode>
</row>

I want to turn into something like this:
<tr>
    <td title="value1">
        blah
    </td>
    <td title="value1\nvalue2">
        blahBlah
    </td>
</tr>

So I'm trying to use the "fn:starts-with" to select these attribute values, but is not quite working.  This is what I have so far:
<xsl:for-each select="row">
    <tr>                        
        <xsl:for-each select="./*">
            <xsl:variable name="title">
                <xsl:for-each select="./@[fn:starts-with(name(),'myattr')]">
                    <xsl:value-of select="."/>
                </xsl:for-each>
            </xsl:variable>
            <td title="$title"><xsl:value-of select="."/></td>
        </xsl:for-each>
    </tr>
</xsl:for-each>

But am getting an exception when I run this.  Any help would be appreciated.

A:

A short and simple transformation:
<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>
 <xsl:strip-space elements="*"/>

 <xsl:template match="/">
  <tr>
   <xsl:apply-templates/>
  </tr>
 </xsl:template>

 <xsl:template match="row/*">
     <td>
      <xsl:apply-templates select="@*[starts-with(name(),'myattr')][1]"/>
      <xsl:value-of select="."/>
     </td>
 </xsl:template>
 <xsl:template match="@*[starts-with(name(),'myattr')][1]">
  <xsl:attribute name="title">
   <xsl:value-of select="."/>
   <xsl:apply-templates select=
    "../@*[starts-with(name(),'myattr')][position()>1]"/>
  </xsl:attribute>
 </xsl:template>

 <xsl:template match="@*[starts-with(name(),'myattr')][position()>1]">
  <xsl:value-of select="concat('\n', .)"/>
 </xsl:template>
</xsl:stylesheet>

when applied on the provided XML document:
<row>
    <anode anotherAttr="notthis" myattr1="value1" >
             blah
  </anode>
    <anothernode anotherAttr="notthis" myattr1="value1" myattr2="value2" >
             blahBlah
 </anothernode>
</row>

the wanted, correct result is produced:
<tr>
   <td title="value1">
             blah
  </td>
   <td title="value1\nvalue2">
             blahBlah
 </td>
</tr>

