...

View Full Version : xsl:for-each



jlafleur
09-05-2008, 11:53 PM
Hi all,

Silly question here, but I'm going insane, and could use an assist.

I have XML that looks like this:


<?xml version="1.0" encoding="UTF-8"?>
<FMPXMLRESULT>
<ERRORCODE>0</ERRORCODE>
<PRODUCT BUILD="11-02-2007" NAME="FileMaker Pro" VERSION="9.0v3"/>
<DATABASE DATEFORMAT="M/d/yyyy" LAYOUT="" NAME="RegistrationProfiles" RECORDS="3" TIMEFORMAT="h:mm:ss a"/>
<METADATA>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="SYS_projectID__g" TYPE="TEXT"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="SYS_programID__g" TYPE="TEXT"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="program_name" TYPE="TEXT"/>
</METADATA>
<RESULTSET FOUND="3">
<ROW MODID="9" RECORDID="9111">
<COL>
<DATA>a</DATA>
</COL>
<COL>
<DATA>b</DATA>
</COL>
<COL>
<DATA>c</DATA>
</COL>
</ROW>
<ROW MODID="9" RECORDID="9112">
<COL>
<DATA>a</DATA>
</COL>
<COL>
<DATA>b</DATA>
</COL>
<COL>
<DATA>c</DATA>
</COL>
</ROW>
<ROW MODID="9" RECORDID="9113">
<COL>
<DATA>a</DATA>
</COL>
<COL>
<DATA>b</DATA>
</COL>
<COL>
<DATA>c</DATA>
</COL>
</ROW>
</RESULTSET>
</FMPXMLRESULT>

And then have a SIMPLE xslt to write "hello world" for each <ROW>.


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:template match="/">
<xsl:for-each select="/FMPXMLRESULT/RESULTSET">
hello world
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>


Yet my output is nada. Why-Oh-Why, true believers, should this be? When I debug, (I'm using Altova XMLSPY V5 rel.4) it walks through my xslt but when it gets to the <xsl:for-each...>, it says "Finished Debugging!"

I think my xpath is correct, what am I missing?

Thank you all,

jlafleur

oesxyl
09-06-2008, 12:10 AM
try:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">

<xsl:output method="text"/>
<xsl:template match="/">
<xsl:apply-template select="/FMPXMLRESULT/RESULTSET"/>
</xsl:template>

<xsl:template match="RESULTSET">
<xsl:for-each select=".">
<xsl:text>hello world
</xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

it's not tested.

best regards

jlafleur
09-06-2008, 02:52 AM
Unfortunately, it didn't work.

oesxyl
09-06-2008, 03:10 AM
Unfortunately, it didn't work.
sorry is my fault. Make this correction:


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">

<xsl:output method="text"/>
<xsl:template match="/">
<xsl:apply-templates select="/FMPXMLRESULT/RESULTSET"/>
</xsl:template>

<xsl:template match="RESULTSET">
<xsl:for-each select="*">
<xsl:text>hello world
</xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

it's tested now and work.

best regards



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum