XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old June 8th, 2003, 10:08 AM
tokind's Avatar
tokind tokind is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: New Mexico
Posts: 31 tokind User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 20 m 55 sec
Reputation Power: 6
Selecting sets of values based on a template

I am having some trouble understanding how to select a set of values based on a template that represents a form in which to present the data.
The Template, part of a form that contains a profile of personal information:
Code:
<myTemplate>
  <topic>Phones</topic>
  <line class="label">
    <phones>
       <input type="TEXT" name="Location" label="Location" size="6"/>
       <input type="TEXT" name="Number" label="Number" size="14"/>
    </phones>
  </line>
</myTemplate>


For each phone from 1 to as many as a returned (say, up to five) I present a field containing a label for the location: Location, and an actual number: Number.

I select this data from a dataset.

Code:
<sql>
  <phoneC>
    <phone>
      <Location>Home</Location>
      <Number>555-555-1212</Number>
    </phone>
    <phone>
      <Location>Work</Location>
      <Number>555-555-1235</Number>
    </phone>
  </phoneC>
</sql>


So, there are two values presented for each <phone>, and this is reflected in the template as a set of fields named "Location" and "Number".

I want each pair of phone input fields to be presented as a set, so they are selected for each ineration of Line. That gives me one phone number (and corresponding Location) per Line.

Code:
<xslt:template match="line/phones">
  <xslt:for-each select="//phones/input">
    <xslt:element name="span">
      <xslt:attribute name="class">label</xslt:attribute>
        <xslt:value-of select="@label"/>
    </xslt:element>/n
    <xslt:element name="input">
      <xslt:attribute name="value">
        <xslt:value-of select="//sql/phoneC/phone[//phones/input/node()]"/>
      </xslt:attribute>
      <xslt:call-template name="attribs"/>
    </xslt:element>\n
  </xslt:for-each>
</xslt:template>


I cannot figure out a valid select statement for this application. For each line/phones/input node I want the value of a /sql/phoneC/phone/identity where that identity correspends to the name of the line/phones/input node. Since there are any from one to say, five phones, I want to innerate throught the sql/phoneC/phones[Location],[Number] sets to output each pair of values on a new line, a new pair of fields.
__________________
Thomas Kindig
http://www.tokind.com
"We are as gods and might as well get good at it." -Stewart Brand

Last edited by tokind : June 8th, 2003 at 10:11 AM.

Reply With Quote
  #2  
Old June 9th, 2003, 03:11 PM
tokind's Avatar
tokind tokind is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: New Mexico
Posts: 31 tokind User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 20 m 55 sec
Reputation Power: 6
Sure.

Code:
<div class="line">
  <input type="TEXT" name="Location" value="Home" />
  <input type="TEXT" name="Number" value="555-555-1212" />
</div>
<div class="line">
  <input type="TEXT" name="Location" value="Work" />
  <input type="TEXT" name="Number" value="555-555-1235" />
</div>

Reply With Quote
  #3  
Old June 9th, 2003, 04:18 PM
tokind's Avatar
tokind tokind is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: New Mexico
Posts: 31 tokind User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 20 m 55 sec
Reputation Power: 6
Hmmm. The system I am developing is a documentation system. All of the documents are about people and events. The "Templates" are forms stored in a database. A given form could be filed out by party A, and it's subject is party B. The particular attributes of the data contained in the form are made up form datasets stored in the database as well.

To blend the data in with the templates would mean writing PHP code each time I need to add a new kind of document to the database. It would require writing new PHP code each time I add attributes to the dataset in the database to accomodate a particular application. If I simply modify an XML/XSL "template", I can produce results on the fly without altering code. I also do not damage the presentation of all of the documents that were stored before I altered the system.

I got several of the transforms to work fine this way. Maybe the problem with this phones construct is that I need to numorate the data:

Code:
<sql>
  <phoneC>
    <phone id="1">
      <Location>Home</Location>
      <Number>...</Number>
    </phone>
    <phone id="2">
      <Location>Home</Location>
      <Number>...</Number>
    </phone>
  </phoneC>
</sql>


?

But let me read what you asked again.

> Can't you generate the required output just from the <sql> section?

From the myTemplate setion, I use the layout information and the label attribute to dictate how my information will be presented (bad design decision?). The <sql> section is written to the template, by PHP, queried from the database, at the time the form is opened by the user.

This works:
The XML
Code:
<form>
  <template>
    <line class="label">
      <nameC>
        <input type="TEXT" label="Hon." name="Honorific" class="FSA" size="3"/>
        <input type="TEXT" label="Name" name="Name" class="FSA" size="26"/>
        <input type="TEXT" label="Title" name="Title" class="FSA" size="16"/>
      </nameC>
    </line>
  </template>
  <sql>
    <nameC>
      <Honorific></Honorific>
      <Name>Thomas E. Kindig</Name>
      <Title>Developer</Title>
    </nameC>
  </sql>
</form>


The Transform
Code:
<... snip>
<xslt:template match="nameC">
  <xslt:for-each select="input">
    <span class="label">
      <xslt:value-of select="@label"/>:</span>
    <xslt:element name="input">
      <xslt:variable name="var">
        <xslt:value-of select="@name"/>
      </xslt:variable>
      <xslt:attribute name="value">
        <xslt:value-of select="//nameC/*[name()=$var]"/>
      </xslt:attribute>
      <xslt:call-template name="attribs"/>
    </xslt:element>
  </xslt:for-each>
</xslt:template>


I get:

Code:
<div class="line">
  <span class="label">Hon.:</span>
    <input value="" type="TEXT" name="Honorific" class="FSA" size="3">
  <span class="label">Name:</span>
    <input value="Thomas E. Kindig" type="TEXT" name="Name" class="FSA" size="26">
  <span class="label">Title:</span>
    <input value="Developer" type="TEXT" name="Title" class="FSA" size="16"></div>


I also have a set of simple values layed out like so:

Code:
<sql>
  <username>tokind</username>
  <password>********</password>
  <nameFirst>Thomas</nameFirst>
  <nameLast>Kindig</nameLast>
  <SSN>444-55-6666</SSN>
  <address>4n7n Somwhere</address>
  <email>thomas@tokind.com</email>
  <localityID>225</localityID>
  <city>LAS CRUCES</city>
  <county>Dona Ana</county>
  <state>NM</state>
  <ZIP>88012</ZIP>
</sql>


With the select

Code:
<xslt:template match="input">
  <xslt:if test="@label">
    <span class="label">
    <xslt:value-of select="@label"/>:</span>
  </xslt:if>
  <xslt:element name="input">
    <xslt:variable name="var">
      <xslt:value-of select="@name"/>
    </xslt:variable>
    <xslt:attribute name="value">
      <xslt:for-each select="//form/sql/*">
        <xslt:if test="name()=$var">
          <xslt:value-of select="."/>
        </xslt:if>
      </xslt:for-each>
    </xslt:attribute>
    <xslt:call-template name="attribs"/>
  </xslt:element>
</xslt:template>


produces all of the editible fields with data in place. I wouldn't care to admit how many hours (days) it took me to figure that out.

I'm about to give up and store those phone numbers in a seperate table. That would, of course, pose another set of design questions.

Last edited by tokind : June 9th, 2003 at 06:24 PM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > Selecting sets of values based on a template


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway