XSL and XML

R

RigasMinho

I have an XSL file that grabs objects to form a table from an XML file.


However I only want it to grab certain objects with a certain tag on
them.


For example:
XML file has:


<infoObject>
<infoObjectDetail title='Field'>Test Field</infoObjectDetail>
<infoObjectDetail title='Description'>Test Desc</infoObjectDetail>
<infoObjectDetail title='Object'>Test Object</infoObjectDetail>
<infoObjectDetail title='Source'>Test Source</infoObjectDetail>
</infoObject>


XSL file:
<xsl:for-each select="infoObjectDetail">
<td><xsl:value-of select="." />  </td>
</xsl:for-each>


I want it so that it skips over the field of "Description" and moves
onto the next field.
I've looked for a for loop to do this but havent had any luck.


Any ideas?
 
P

p.lepin

RigasMinho said:
However I only want it to grab certain objects with a
certain tag on them.

And the problem is..?
XML file has:

<infoObject>
<infoObjectDetail title='Field'>Test
Field</infoObjectDetail>
<infoObjectDetail title='Description'>Test
Desc</infoObjectDetail>
<infoObjectDetail title='Object'>Test
Object</infoObjectDetail>
<infoObjectDetail title='Source'>Test
Source</infoObjectDetail>
</infoObject>

XSL file:

<xsl:for-each select="infoObjectDetail">
<td><xsl:value-of select="." />  </td>
</xsl:for-each>

I want it so that it skips over the field of
"Description" and moves onto the next field. I've looked
for a for loop to do this but havent had any luck.

Any ideas?

Lots, actually. First of all, I would recommend reading
some XSLT and XPath tutorials.

As to your problem, you could either persist in your
attempts to stick imperative paradigm to XSLT and use the
following:

<xsl:if test="@title!='Description'">
<td><xsl:value-of select="." />  </td>
</xsl:if>

....or you could try to adapt and do the Right Thing. Drop
for-each, define a template:

<xsl:template match="infoObjectDetail">
<td><xsl:value-of select="."/> </td>
</xsl:template>

Then use apply-templates to process the nodes you need.

<xsl:apply-templates
select="//infoObjectDetail[@title!='Description']"/>

Or even better, select all the nodes, and use predicates to
define corresponding templates (empty template for
infoObjectDetail[@title='Description'] etc.)

And the last thing: read some XSLT and XPath tutorials.
Toying with Lisp or Scheme or [foo nctional language of
your choice] is also highly recommended.

Oh, and forget the 'for loops'.

Did I mention tutorials?
 

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

No members online now.

Forum statistics

Threads
474,005
Messages
2,570,264
Members
46,859
Latest member
HeidiAtkin

Latest Threads

Top