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: AW: XSL equivalent to SQL "unique"


Hi Frank,

this solution assumes an XML input like this:
<root>
        <set name="1">
                <a>v1</a>
                <c>v2</c>
                <d>v3</d>
        </set>
        <set name="2">
                <a>v4</a>
                <b>v5</b>
                <e>v6</e>
        </set>
        <set name="3">
                <b>v7</b>
                <f>v8</f>
        </set>
</root>

Ok, here you go (maybe not optimal, but it works):

<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

<xsl:key name="cols" use="name()" match="set/*" />

<xsl:variable name="cols" 
              select="//set/*[count(.|key('cols',name())[1]) = 1]" />

<xsl:template match="root">
   <html><body><table border="1">
      <tr><td />
         <xsl:for-each select="$cols">
            <xsl:sort select="name()" />
            <th>
               <xsl:value-of select="name()" />
            </th>
         </xsl:for-each>
      </tr>
      <xsl:apply-templates />
   </table></body></html>
</xsl:template>

<xsl:template match="set">
   <tr>
      <th>
         <xsl:value-of select="@name" />
      </th>
      <xsl:variable name="entries" select="*" />
      <xsl:for-each select="$cols">
         <xsl:sort select="name()" />
         <td>
            <xsl:value-of select="$entries[name() = name(current())]" />
         </td>
      </xsl:for-each>
   </tr>
</xsl:template>

</xsl:stylesheet>


Perhaps Jeni will have a break and post some explanations on how to solve
problems like yours ;-)

Cheers,
Oliver


Original message:
> > I've spent some time to figure out an easy way to solve the following
> > problem and failed, maybe some Guru can give me a clue?
> > 
> > Having XML input like
> > 
> > 	<set name="1">
> > 		<a>v1</a>
> > 		<c>v2</c>
> > 		<d>v3</d>
> > 	</set>
> > 	<set name="2">
> > 		<a>v4</a>
> > 		<b>v5</b>
> > 		<e>v6</e>
> > 	</set>
> > 	<set name="3">
> > 		<b>v7</b>
> > 		<f>v8</f>
> > 	</set>
> > 
> > I need to render a quadratic schema like
> > 
> > 		a 	b 	c 	d 	e 	f
> > 	1	v1		v2	v3
> > 	2	v4	v5			v6
> > 	3		v7				v8
> > 
> > in HTML, i.e., I need output like
> > 
> > 	<table>
> > 
> > <tr><td></td><td>a</td><td>b</td><td>c</td><td>d</td><td>e</td
> > ><td>f</td></t
> > r>
> > 
> > <tr><td>1</td><td>v1</td><td></td><td>v2</td><td>v3</td><td></
> > td><td></td></
> > tr>
> > 
> > <tr><td>2</td><td>v4</td><td>v5</td><td></td><td></td><td>v6</
> > td><td></td></
> > tr>
> > 
> > <tr><td>3</td><td></td><td>v7</td><td></td><td></td><td></td><
> > td>v8</td></tr
> > >
> > 	</table>
> > 
> > Of course all dimensions are variable dependand on underlying
> > data. I thought, the problem boils down to obtaining the a list like
> > 
> > 	<n>a</n><n>b</n><n>c</n><n>d</n><n>e</n><n>f</n>
> > 
> > in a variable from the initial input. But I failed to obtain 
> > that, though
> > I'm fairly sure it has to "be there" :-(
> > 
> > Any help?
> > 
> > Thank you very much,
> > Frank

/-------------------------------------------------------------------\
|  ob|do        Dipl.Inf. Oliver Becker                             |
|  --+--        E-Mail: obecker@informatik.hu-berlin.de             |
|  op|qo        WWW:    http://www.informatik.hu-berlin.de/~obecker |
\-------------------------------------------------------------------/


 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]