This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Merging data (two xml documents, two context nodes)
- From: "McKeever, Marty" <marty dot mckeever at bankofamerica dot com>
- To: xsl-list at lists dot mulberrytech dot com
- Date: Tue, 18 Dec 2001 09:22:30 -0500
- Subject: [xsl] Merging data (two xml documents, two context nodes)
- Reply-to: xsl-list at lists dot mulberrytech dot com
I'm creating an application to build up a data.xml file, where the interface
is created via XSLT by combining the structure of a config.xml with the
values contained in the data.xml being created. The interface is the
output. For example:
data.xml
<page name="foo" type="A"></page>
the name and type attributes are populated via the interface created
from config.xml
config.xml
<page>
<attributes>
<attribute attname="name" widget="text"/>
<attribute attname="type" widget="select">
<option value="PR">Press Release</option>
<option value="A">Article</option>
</attribute>
</attributes>
</page>
So, while parsing the data.xml in interface.xsl I have the following
template:
<xsl:template match="page">
Page Options:
<xsl:call-template name="makeAttributes">
<xsl:with-param name="prefix">page</xsl:with-param>
</xsl:call-template>
</xsl:template>
Template "makeAttributes" then reads the config file to create the
interface:
<xsl:template name="makeAttributes">
<xsl:param name="prefix"/>
<xsl:for-each
select="document('config.xml')/page/attributes/attribute">
<xsl:if test="@widget='text'">
<input type="text" name="{$prefix}|{@attname}"
value="{??? value "foo" from data.xml/page/@name ???}" />
</xsl:if>
<xsl:if test="@widget='select'">
<select name="{$prefix}|{@attname}">
<xsl:for-each select="option">
<option value="{@value}">
<xsl:if test="@value=??? value "A" from
data.xml/page/@type ???">
<xsl:attribute
name="selected">selected</xsl:attribute>
</xsl:if>
<xsl:value-of select="."/></option>
</xsl:for-each>
</select>
</xsl:if>
</xsl:for-each>
</xsl:template>
So the problem here is how to read data from the original context node
(data.xml/page) after the called template has changed its context to
congfig.xml/page/attributes/attribute?
I think (hope) i'm just missing something simple...
Suddenly i'm wondering if i should be parsing config.xml as the base
document, and modifying it according to the contents of data.xml, instead if
the other way around.
Thanks for any comments,
Marty
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list