SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Guru
    Join Date
    Dec 1999
    Location
    Southampton, Hants, UK
    Posts
    672
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    My XSLT and XML doesn't work

    I am having a mare trying to get 1 particular xslt working with my xml, the xslt is as follows:

    Code:
     <xsl:stylesheet version='1.1' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
     	<xsl:template match='/stylesheet'>
     	
     		<!-- Start Document Control Output -->
     		<div class="viewelement">
     			<div class="viewtitle">Document Control</div>
     			<ul class="documentcontrol">
     		    	<xsl:for-each select="documentcontrol/modifier">
     		    		<li><xsl:value-of select="modifier" /></li>
     				</xsl:for-each>
     			</ul>
     		</div>
     		<!-- End Document Control Output -->
     	
     	</xsl:template>	
     </xsl:stylesheet>
    my xml is as follows:
    Code:
     <stylesheet>
     	<documentcontrol>
     		<modifier>Joe Bloggs1 on 12-03-04 at 12:45</modifier>
     		<modifier>Joe Bloggs2 on 12-03-04 at 12:45</modifier>
     		<modifier>Joe Bloggs3 on 12-03-04 at 12:45</modifier>
     		<modifier>Joe Bloggs4 on 12-03-04 at 12:45</modifier>
     	</documentcontrol>
     
     	<content>
     		<![CDATA[
     			body { background: #fff }
     		]]>
     	</content>
     </stylesheet>
    Basically, I'm getting 4 blank bullets!!! Doh! what am i doing wrong?

  2. #2
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    With this code:
    Code:
    <ul class="documentcontrol">
     		    	<xsl:for-each select="documentcontrol/modifier">
     		    		<li><xsl:value-of select="modifier" /></li>
     				</xsl:for-each>
     			</ul>
    You're basically saying "output any modifier elements that are inside of a modifier that are inside of a documentcontrol". You're really close though. Here's the working version:
    Code:
    <ul class="documentcontrol">
     		    	<xsl:for-each select="documentcontrol/modifier">
     		    		<li><xsl:value-of select="." /></li>
     				</xsl:for-each>
     			</ul>
    This code says "loop through each modifier in documentcontrol, then spit out the current node's value" (so it doesn't look for any element nested in the modifier element).


Bookmarks

Posting Permissions

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