This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Using a second xml document as a lookup table
- From: John Sands <WonkoWatson at Yahoo dot com>
- To: xsl-list at lists dot mulberrytech dot com
- Date: Thu, 9 May 2002 20:08:59 -0400
- Subject: Re: [xsl] Using a second xml document as a lookup table
- References: <3237952031.20020509171459@Yahoo.com> <3CDB0475.8020103@gmx.de>
- Reply-to: xsl-list at lists dot mulberrytech dot com
Thanks Joerg - your xsl:if is just what I needed. You're right, I
don't need the = and the extra dbcolumn. Now I get just a
comma-delimited list of column names that are defined in the dbdef
document. Perfect.
> -----Original Message-----
> From: Joerg Heinicke <joerg.heinicke@gmx.de>
> Sent: Thursday, May 9, 2002, 7:21:25 PM,
> Subject: [xsl] Using a second xml document as a lookup table
> Hello John,
> almost everything is ok, you are switching the context correctly to the
> second file dbdef.xml, you are only selecting the text-value of a node,
> that has no text.
> With your <xsl:value-of select="$dbdef-col"/> at the end you select the
> text of an element <AttributeType/>, they all are empty (have no child
> nodes) in your dbdef.xml. What you want is maybe <xsl:value-of
> select="$dbdef-col/@name"/>, isn't it?
> But your code is not completely full of sense to me. Can the test not be
> done easier?
> <xsl:template match="columns">
> <xsl:for-each select="column">
> <xsl:variable name="dbcolumn" select="@dbcolumn"/>
> <xsl:for-each select="$dbdef">
> <xsl:if test="key('dbdef-cols', $dbcolumn)">
> <xsl:value-of select="$dbcolumn"/>
> <xsl:text>=</xsl:text>
> <xsl:value-of select="$dbcolumn"/>
> <xsl:text>,</xsl:text>
> </xsl:if>
> </xsl:for-each>
> </xsl:for-each>
> </xsl:template>
> You have something like ID and IDREF. You don't need to output as first
> the one and as second the other one. The value is the same. So the
> <xsl:if> is important. Or do you need the
> "col1=,col2=col2,col3=col3"-String?
> Regards,
> Joerg
>> Here's my main XML file:
>>
>> <columns>
>> <column dbcolumn="col1"/>
>> <column dbcolumn="col2" />
>> <column dbcolumn="col3" />
>> </columns>
>>
>> Here's my lookup XML file, dbdef.xml:
>>
>> <ElementType>
>> <AttributeType name='col2'/>
>> <AttributeType name='col3' />
>> <AttributeType name='col4' />
>> </ElementType>
> >
>> My XSLT is:
>>
>> <xsl:key name="dbdef-cols" match="AttributeType" use="@name" />
>> <xsl:variable name="dbdef" select="document('dbdef.xml')" />
>>
>> <xsl:template match="/">
>> <xsl:variable name="all-columns" select="//column"/>
>> <xsl:for-each select="$all-columns">
>> <xsl:variable name="dbcolumn" select="@dbcolumn" />
>> <xsl:for-each select="$dbdef">
>> <xsl:variable name="dbdef-col" select="key('dbdef-cols', $dbcolumn)" />
>> <xsl:value-of select="$dbcolumn"/>=<xsl:value-of select="$dbdef-col"/>,
>> </xsl:for-each>
>> </xsl:for-each>
>> </xsl:template>
> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list