Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4

Thread: xsl:for-each

  1. #1
    New to the CF scene
    Join Date
    Sep 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    xsl:for-each

    Hi all,

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

    I have XML that looks like this:
    Code:
    <?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>.

    Code:
    <?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

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    try:
    Code:
    <?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

  • #3
    New to the CF scene
    Join Date
    Sep 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    So sad...

    Unfortunately, it didn't work.

  • #4
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by jlafleur View Post
    Unfortunately, it didn't work.
    sorry is my fault. Make this correction:

    Code:
    <?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
    Last edited by oesxyl; 09-06-2008 at 03:36 AM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •