K.O.
The xml is comprozed of a stored "template that defines the contents and layout of the product, and the results of an sql query that comprses the information the product is displaying.
Code:
<form>
<template>
<title>My Profile</title>
<para class="instructions"> You may input your personal information here. When you have made the desired changes, click the Update Profile button at the bottom to save your information to the system.</para>
<table name="People" class="tableSet">
<topic>Name</topic>
<line class="label">
<input type="TEXT" label="First" name="nameFirst" class="FSA"/>
<input type="TEXT" label="Last" name="nameLast" class="FSA"/>
</line>
<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>
<topic>Address</topic>
<line class="label">
<input type="TEXT" label="Street" name="address" class="FSA"/>,
<input type="TEXT" name="city" class="FSA" size="12"/>,
<input type="TEXT" name="state" class="FSA" size="2"/>
<input type="TEXT" name="ZIP" class="FSA" size="12"/>
</line>
<line class="label">
<input type="TEXT" label="Email Address" name="email" class="FSA"/>
<input type="TEXT" label="SSN (Private)" name="SSN" size="12" class="FSA"/>
</line>
<topic>Phones</topic>
<line class="label">
<phones>
<input type="TEXT" name="Location" label="Location" class="FSA" size="6"/>
<input type="TEXT" name="Number" label="Number" class="FSA" size="14"/>
</phones><!-- input type="TEXT" name="aLocation" label="Location" class="FSD" size="6"/>
<input type="TEXT" name="aNumber" label="Number" class="FSA" size="14"/ -->
</line>
</table>
<table name="Accounts" class="tableSet">
<topic>Account</topic>
<line class="label">
<input type="TEXT" name="username" label="Member ID" disabled="DISABLED" class="FSD" size="18"/>
<input type="PASSWORD" label="Password" name="password" class="FSA"/>
</line>
<line class="label">
<input type="SUBMIT" name="action" value="Update Profile" checked="checked" class="FSB"/>
</line>
</table>
</template>
<sql>
<username>toofriendly</username>
<password>make8ice</password>
<nameFirst>Frankie</nameFirst>
<nameLast>Jones</nameLast>
<nameC>
<val name="Honorific">Dr.</val>
<val name="Name">Franklin Samuel Jones</val>
<val name="Title">PHD</val>
</nameC>
<SSN>nnn-nn-nnnn</SSN>
<address>4276 Some St</address>
<phoneC>
<phone>
<Location>Home</Location>
<Number>505-555-1212</Number>
</phone>
<phone>
<Location>Work</Location>
<Number>505-644-1212</Number>
</phone>
</phoneC>
<email>me@erg.com</email>
<localityID>225</localityID>
<city>Los Crevices</city>
<county>Dana</county>
<state>NM</state>
<ZIP>88912</ZIP>
</sql>
</form>
Note that "form" is the root, and the dataset is inserted as set "sql".
The transform does layout duties like a stylsheet template, but must insert values in the form contents; values selected from the sql node set. I am populating a form with data.
The xslt:
Code:
<xslt:transform xmlns:xslt="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform"[/URL] version="1.0">
<xslt:output method="html" omit-xml-declaration="yes"/>
<xslt:template match="template">
<xslt:element name="form">
<xslt:attribute name="method">POST</xslt:attribute>
<xslt:apply-templates/>
</xslt:element>
</xslt:template><!-- begin segment processing -->
<xslt:template match="table">
<xslt:element name="div">
<xslt:attribute name="name">
<xslt:value-of select="@name"/>
</xslt:attribute>
<xslt:attribute name="class">tableSet</xslt:attribute>
<xslt:apply-templates/>
</xslt:element>
</xslt:template>
<xslt:template match="line">
<xslt:element name="div">
<xslt:attribute name="class">line</xslt:attribute>
<xslt:apply-templates/>
</xslt:element>
</xslt:template>
<xslt:template match="set">
<xslt:for-each select="set">
<xslt:apply-templates/>
</xslt:for-each>
</xslt:template><!-- specific node processing -->
<xslt:template match="sql"><!-- returns nothing for data set values -->
</xslt:template>
<xslt:template match="title">
<xslt:element name="h1">
<xslt:value-of select="."/>
</xslt:element>
</xslt:template>
<xslt:template match="para">
<xslt:element name="p">
<xslt:attribute name="class">
<xslt:value-of select="@class"/>
</xslt:attribute>
<xslt:value-of select="."/>
</xslt:element>
</xslt:template>
<xslt:template match="topic">
<xslt:element name="h2">
<xslt:attribute name="class">topic</xslt:attribute>
<xslt:value-of select="."/>
</xslt:element>
</xslt:template>
<xslt:template match="line/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="//sql/*[//line/input[$var]]"/>
</xslt:attribute>
<xslt:call-template name="attribs"/>
</xslt:element>
</xslt:template>
<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/val[@name=$var]"/>
</xslt:attribute>
<xslt:call-template name="attribs"/>
</xslt:element>
</xslt:for-each>
</xslt:template>
<xslt:template match="phones">
<xslt:for-each select="//sql/phoneC/phone">
<xslt:call-template name="phone"/>
<br/>
</xslt:for-each>
</xslt:template>
<xslt:template name="phone">
<xslt:for-each select="phones/input">
<xslt:element name="span">
<xslt:attribute name="class">
<xslt:value-of select="@label"/>
</xslt:attribute>
</xslt:element>\n
<xslt:element name="input">
<xslt:variable name="var">
<xslt:value-of select="//*/phone/."/>
</xslt:variable>
<xslt:attribute name="value">
<xslt:value-of select="//phone/."/>
</xslt:attribute>
<xslt:attribute name="type">
<xslt:value-of select="//*/phones/input/@type"/>
</xslt:attribute>
<xslt:attribute name="name">
<xslt:value-of select="@name"/>
</xslt:attribute>
<xslt:attribute name="class">
<xslt:value-of select="//*/phones/input/@class"/>
</xslt:attribute>
<xslt:if test="//*/phones/input/@size">
<xslt:attribute name="size">
<xslt:value-of select="//*/phones/input/@size"/>
</xslt:attribute>
</xslt:if>
</xslt:element></xslt:for-each>
</xslt:template><!-- attribs completes input node attributes for all input fileds -->
<xslt:template name="attribs">
<xslt:attribute name="type">
<xslt:value-of select="@type"/>
</xslt:attribute>
<xslt:attribute name="name">
<xslt:value-of select="@name"/>
</xslt:attribute>
<xslt:attribute name="class">
<xslt:apply-templates select="@class"/>
</xslt:attribute>
<xslt:if test="@size">
<xslt:attribute name="size">
<xslt:value-of select="@size"/>
</xslt:attribute>
</xslt:if>
<xslt:if test="@disabled">
<xslt:attribute name="disabled">
<xslt:value-of select="@disabled"/>
</xslt:attribute>
</xslt:if>
</xslt:template>
</xslt:transform>
Now here is the XHTML product.
Code:
<form method="POST">
<h1>My Profile</h1>
<p class="instructions"> You may input your personal information here. When you have made the desired changes, click the Update Profile button at the bottom to save your information to the system.</p>
<div name="People" class="tableSet">
<h2 class="topic">Name</h2>
<div class="line"><span class="label">First:</span><input value="toofriendly" type="TEXT" name="nameFirst" class="FSA"><span class="label">Last:</span><input value="toofriendly" type="TEXT" name="nameLast" class="FSA"></div>
<div class="line"><span class="label">Hon.:</span><input value="Dr." type="TEXT" name="Honorific" class="FSA" size="3"><span class="label">Name:</span><input value="Franklin Samuel Jones" type="TEXT" name="Name" class="FSA" size="26"><span class="label">Title:</span><input value="PHD" type="TEXT" name="Title" class="FSA" size="16"></div>
<h2 class="topic">Address</h2>
<div class="line"><span class="label">Street:</span><input value="toofriendly" type="TEXT" name="address" class="FSA">,
<span class="label">:</span><input value="toofriendly" type="TEXT" name="city" class="FSA" size="12">,
<span class="label">:</span><input value="toofriendly" type="TEXT" name="state" class="FSA" size="2"><span class="label">:</span><input value="toofriendly" type="TEXT" name="ZIP" class="FSA" size="12"></div>
<div class="line"><span class="label">Email Address:</span><input value="toofriendly" type="TEXT" name="email" class="FSA"><span class="label">SSN (Private):</span><input value="toofriendly" type="TEXT" name="SSN" class="FSA" size="12"></div>
<h2 class="topic">Phones</h2>
<div class="line"><br><br></div>
</div>
<div name="Accounts" class="tableSet">
<h2 class="topic">Account</h2>
<div class="line"><span class="label">Member ID:</span><input value="toofriendly" type="TEXT" name="username" class="FSD" size="18" disabled><span class="label">Password:</span><input value="toofriendly" type="PASSWORD" name="password" class="FSA"></div>
<div class="line"><span class="label">:</span><input value="toofriendly" type="SUBMIT" name="action" class="FSB"></div>
</div>
</form>
Instead of selecting a node from <sql> based on the @name of the <template> element, I am getting the FIRST element of the <sql> set with each select. I have tried various @node, node()=$var, and explicite selections like //sql/*[//template*/input/@name] to no avail.
I have managed to get something working by adding a name attribute to each <sql> node a la:
Code:
<sql>
<username name="username">toofriendly</username>
<password name="password">make8ice</password>
<nameFirst name="nameFirst">Frankie</nameFirst>
<nameLast name="nameLast">Jones</nameLast>
</sql>
and select on //sql/*[@name=$var]
which of course defeats the purpose of xml, huh?
Sorry about the language. I'm still getting the hang of it. I've only been doing this for two weeks.