- From: Stuart Brown <sbrown@extenza.com>
- Date: Wed, 8 Oct 2003 14:54:32 +0100
- To: "'www-forms@w3.org'" <www-forms@w3.org>
- Message-ID: <F0FDC1207BD1D7118F8A00508B8BA22B2451AD@sbis-uk-1.uk.swetsblackwell.com>
Hi,
This is my first foray into XForms, and I'm trying to do some conditional
value assignment.
The form loads two sets of instance data: one is the eventual output
(extenza.xml), which describes one journal article; and one contains details
of all the possible journals so that the selection of a journal will
populate all the relevant pieces of data in extenza.xml from the selected
journal in journals.xml.
<xf:model id="extenza">
<xf:instance id="extenza" src="extenza-template.xml"/>
<xf:instance id="journals" src="journals.xml"/>
</xf:model>
The relevant bits of the source XML look as follows:
extenza-template.xml:
<Extenza xmlns="http://www.extenza.com/xml-def">
<ArticleMetadata>
<SerialItemRecord>
<!-- ISSN -->
<SerialTitleIdentifier>
<SerialTitleIDType>ISSN</SerialTitleIDType>
<IDValue></IDValue>
</SerialTitleIdentifier>
<!-- CODEN -->
<SerialTitleIdentifier>
<SerialTitleIDType>CODEN</SerialTitleIDType>
<IDValue></IDValue>
</SerialTitleIdentifier>
<Title>
<TitleText></TitleText>
</Title>
<!-- Other stuff -->
</SerialItemRecord>
</ArticleMetadata>
</Extenza>
journals.xml:
<journals>
<journal>
<title>My Journal</title>
<issn>1234-5678</issn>
<coden>ABCDEFG</coden>
</journal>
<journal>
<title>Another Journal</title>
<issn>8765-4321</issn>
</journal>
<!-- And others -->
</journal>
The problem is that I want, on selection of a journal in the first case of
the form, to set the ISSN and CODEN to the respective <IDValue> elements in
the source XML. However, not all journals have a CODEN, and in the event of
this I want to remove the second occurrence of <SerialTitleIdentifier> in
the instance data for output (or, alternatively, to have it absent in the
source XML, and insert the second occurrence in the positive case of a
CODEN). I am currently working on having used a <select1> option to
populate the <TitleText> element with the journal title, and then in the
action to move to the next case of the form, <setvalue> is used to assign
the remaining data.
<xf:switch>
<xf:case id="journalSelect">
<!-- Select the journal and bind its title to the TitleText in extenza
-->
<xf:select1 appearance="minimal" instance="extenza"
ref="ex:ArticleMetadata/ex:SerialItemRecord/ex:Title/ex:TitleText">
<xf:label>Select journal:</xf:label>
<xf:itemset nodeset="instance('journals')/journal">
<xf:label ref="title"/>
<xf:value ref="title"/>
</xf:itemset>
</xf:select1>
<br/>
<br/>
<xf:trigger>
<xf:label>OK</xf:label>
<!-- On the trigger to move to the next case I assign the remaining
values -->
<xf:action ev:event="DOMActivate">
<!-- Set the ISSN -->
<xf:setvalue instance="extenza"
ref="ex:ArticleMetadata/ex:SerialItemRecord/ex:SerialTitleIdentifier[1]/ex:I
DValue" value="instance('journals')/journal[title =
instance('extenza')/ex:ArticleMetadata/ex:SerialItemRecord/ex:Title/ex:Title
Text]/issn"/>
<!-- ** Here I want to check if there is a <coden> child of the
selected <journal> and, if there is, assign similar to above, and if there
isn't to remove the second occurrence of <SerialTitleIdentifier> from the
instance ** -->
<xf:toggle case="confirm1"/>
</xf:action>
</xf:trigger>
</xf:case>
<xf:case id="confirm1">
<!-- Next step... --->
</xf:case>
</xf:switch>
I can't find anything about how to do this on lists or in Micah Dubinko's
book.
Any suggestions? Am I going about this entirely the wrong way in the first
place? A generic explanation of this kind of processing would be very
gratefully appreciated, as there are a lot more of this kind of problem
going to crop up for me (later in the form, for instance, I want to bind a
value to one of two elements depending on whether it is an integer or NaN).
Thanks,
Stuart
Stuart Brown
Electronic Production Manager
Extenza e-Publishing Services
a Division of Swets & Zeitlinger
32 Blacklands Way
Abingdon Business Park
Abingdon, Oxon
OX14 1SX
t: +44 (0) 1235 857739
f: +44 (0) 1235 857752
e: sbrown@extenza.com
w: www.extenza-eps.com <www.extenza-eps.com>
Received on Wednesday, 8 October 2003 10:01:00 UTC