By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,617 Members | 1,792 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,617 IT Pros & Developers. It's quick & easy.

Help/Advice with XSL / XPath needed

P: n/a
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:
XML SNIPPET >>>> <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: XSL >>>>

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:output 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
Jul 20 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a

"Philip" <pl**********@statestreet.com> wrote in message
news:21**************************@posting.google.c om...
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
Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.