Help/Advice with XSL / XPath needed

P

Philip

Hi,

I am trying to output certain nodes inside another. I have an xml
template with field definitions for a form, and this includes
textfields, labels, checkboxes etc plus fieldssets. I defined them
like
this:
<fields>
<field>
<name>lAccount_Num</name>
<id>lAccount_Num</id>
<legend />
<caption>Account Number:</caption>
<type>label</type>
<size />
<style>LEFT: 17px; WIDTH: 112px; POSITION: absolute; TOP: 35px;
HEIGHT:
18px</style>
<FOR>tAccount_Num</FOR>
<maxLength />
<parentFieldSet>fstFields</parentFieldSet>
<value />
</field>

....

<field>
<name>lEnabled</name>
<id>lEnabled</id>
<caption>Enabled:</caption>
<legend />
<type>label</type>
<size />
<style>LEFT: 330px; WIDTH: 120px; POSITION: absolute; TOP: 100px;
HEIGHT: 18px</style>
<FOR>chEnable</FOR>
<parentFieldSet />
<maxLength />
<value />
</field>

....

<field>
<name>fstFields</name>
<id>fstFields</id>
<legend>Account Date</legend>
<caption />
<type>fieldset</type>
<size />
<style>LEFT: 8px; WIDTH: 484px; POSITION: absolute; TOP: 12px; HEIGHT:
124px</style>
<FOR />
<parentFieldSet>fstFields</parentFieldSet>
<maxLength />
<value />
</field>
</fields>
<<<<< END XML SNIPPET <<<

so you can see I have a field nodes with a defined parentFieldSet, a
field nodes with no defined fieldset, and a fieldset node.

What I want is to use an XPath expresion in my match / apply-templates
to output the start tag of the FieldSet, then go and find all the
nodes
with that parentFieldSet name defined, then output the end tag of the
fieldset, following that we do the next fieldset (if any) and finally
output all the fields with no parentFieldSet defined.

Here is my XSL so far:<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:eek:utput method="html" version="1.0" omit-xml-declaration="no"
standalone="no" indent="yes" />
<xsl:template match="/">
<html>
<body bgcolor="#dddddd">
<!-- field[parentFieldSet='fstFields']/-->
<xsl:apply-templates select="fields/field"/>
</body>
</html>

</xsl:template>

<xsl:template match="field">
<xsl:choose>
<xsl:when test="./type='Text'">
<input type="text">
<xsl:attribute name="name">
<xsl:value-of select="name" />
</xsl:attribute>
<xsl:attribute name="id">
<xsl:value-of select="id" />
</xsl:attribute>
<xsl:attribute name="FOR">
<xsl:value-of select="FOR" />
</xsl:attribute>
<xsl:attribute name="style">
<xsl:value-of select="style" />
</xsl:attribute>
<xsl:if test="./maxlength !=''">
<xsl:attribute name="maxlength">
<xsl:value-of select="maxlength" />
</xsl:attribute>
</xsl:if>
<xsl:if test="./size != ''">
<xsl:attribute name="size">
<xsl:value-of select="size" />
</xsl:attribute>
</xsl:if>
</input>
</xsl:when>
<xsl:when test="./type='fieldset'">
<fieldset>
<xsl:attribute name="name">
<xsl:value-of select="name" />
</xsl:attribute>
<xsl:attribute name="id">
<xsl:value-of select="id" />
</xsl:attribute>
<xsl:attribute name="FOR">
<xsl:value-of select="FOR" />
</xsl:attribute>
<xsl:attribute name="style">
<xsl:value-of select="style" />
</xsl:attribute>
<xsl:if test="./maxlength !=''">
<xsl:attribute name="maxlength">
<xsl:value-of select="maxlength" />
</xsl:attribute>
</xsl:if>
<xsl:if test="./size != ''">
<xsl:attribute name="size">
<xsl:value-of select="size" />
</xsl:attribute>
</xsl:if>
<xsl:if test="./legend != ''">
<legend>
<xsl:value-of select="legend" />
</legend>
</xsl:if>
</fieldset>
</xsl:when>
<xsl:when test="./type = 'label'">
<label>
<xsl:attribute name="name">
<xsl:value-of select="name" />
</xsl:attribute>
<xsl:attribute name="id">
<xsl:value-of select="id" />
</xsl:attribute>
<xsl:attribute name="FOR">
<xsl:value-of select="FOR" />
</xsl:attribute>
<xsl:attribute name="style">
<xsl:value-of select="style" />
</xsl:attribute>
<xsl:if test="./maxlength !=''">
<xsl:attribute name="maxlength">
<xsl:value-of select="maxlength" />
</xsl:attribute>
</xsl:if>
<xsl:if test="./size != ''">
<xsl:attribute name="size">
<xsl:value-of select="size" />
</xsl:attribute>
</xsl:if>
<xsl:value-of select="caption" />
</label>
</xsl:when>
<xsl:when test="./type='Checkbox'">
<input type="checkbox">
<xsl:attribute name="id">
<xsl:value-of select="id" />
</xsl:attribute>
<xsl:attribute name="name">
<xsl:value-of select="name" />
</xsl:attribute>
<xsl:attribute name="style">
<xsl:value-of select="style" />
</xsl:attribute>
</input>
</xsl:when>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
<<<< END XSL <<<

It outputs all the fields, but doesn't care which ones are supposed to
be inside the fielddset.

This is so that I can reuse my XSL/ASP with multiple form definition
templates built in XML...then I can realize the age old dream of
separating content from structure, and even processing code from
content
and structure...yay

I'd be grateful for any assistance or help or ideas

Philip
 
K

Kenneth Stephen

Philip said:
Hi,

I am trying to output certain nodes inside another. I have an xml
template with field definitions for a form, and this includes
textfields, labels, checkboxes etc plus fieldssets. I defined them
like
this:
Hi,

Seems to me that what you need is :

<xsl:for-each select="fields">
<xsl:apply-templates select="field" />
</xsl:for-each>

...and this should replace the line that you currently have :

<xsl:apply-templates select="fields/field"/>

Regards,
Kenneth
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,019
Latest member
RoxannaSta

Latest Threads

Top