SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Enthusiast revelstoke's Avatar
    Join Date
    Sep 2004
    Posts
    41
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How do I add an HTML break to this?

    Code:
    <grant>
      <Deadlines>
         <anyType xsi:type="xsd:string">04.05.05</anyType> 
         <anyType xsi:type="xsd:string">03.01.06</anyType> 
         <anyType xsi:type="xsd:string">03.01.07</anyType> 
         <anyType xsi:type="xsd:string">10.15.07</anyType> 
      </Deadlines>
    </grant>
    All I want to do, is code my XSL to parse through the Deadlines parent, and after each Deadline-child (the date...)insert an html break so the output is

    04.05.05
    03.01.06
    03.01.07
    10.15.07

    Instead of, this like it is now:

    04.05.0503.01.0603.01.0710.15.07

  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)
    HTML Code:
    <xsl:template match="/">
    <xsl:for-each select="Deadlines/anyType">
      <xsl:value-of select="."/><br/>
    </xsl:for-each>
    </xsl:template>

  3. #3
    SitePoint Enthusiast revelstoke's Avatar
    Join Date
    Sep 2004
    Posts
    41
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <h2>Related Grants</h2>
    <xsl:apply-templates select="//go:Grant"/>
    
    </xsl:template>
    	<xsl:template match="go:Grant">
    		<xsl:for-each select="Deadlines/anyType">
    		  <xsl:value-of select="."/><br/>
    		</xsl:for-each>
    	</xsl:template>
    </xsl:stylesheet>
    Still isnt working, not sure where im going wrong?

    Thank you for any and all help though, greatly appreciated.

  4. #4
    $this->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Dec 2003
    Location
    Federal Way, Washington (USA)
    Posts
    1,524
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't think you can have child nodes with the same name underneath the same parent. I modified your XML file like so:

    Code:
    <grant>
      <Deadlines>
         <anyType1>04.05.05</anyType1> 
         <anyType2>03.01.06</anyType2> 
         <anyType3>03.01.07</anyType3> 
         <anyType4>10.15.07</anyType4> 
      </Deadlines>
    </grant>
    Then used this stylesheet to get the display to come out right:

    Code:
    <xsl:template match="/">
    <xsl:for-each select="grant/Deadlines">
      <xsl:value-of select="anyType1" /><br/>
      <xsl:value-of select="anyType2" /><br/>
      <xsl:value-of select="anyType3" /><br/>
      <xsl:value-of select="anyType4" /><br/>
    </xsl:for-each>
    </xsl:template>
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    Showcase your music collection on the Web

  5. #5
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by vinyl-junkie
    I don't think you can have child nodes with the same name underneath the same parent. I modified your XML file like so:
    Yeah you can, otherwise we wouldn't be able to use HTML very well:
    Code:
    <div id="content">
    <p>...</p>
    <p>...</p>
    <p>...</p>
    </div>

  6. #6
    $this->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Dec 2003
    Location
    Federal Way, Washington (USA)
    Posts
    1,524
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by vgarcia
    Yeah you can, otherwise we wouldn't be able to use HTML very well:
    Fair enough, but the code you posted still doesn't display like the original poster wanted it; i.e., one value per line.

    I tried this for the stylesheet:

    Code:
    <xsl:template match="/">
    <xsl:for-each select="grant/Deadlines">
      <xsl:value-of select="anyType" /><br/>
    </xsl:for-each>
    </xsl:template>
    but all that displayed was the first element. That's why I renamed the child nodes like I did.

    The question remains though - How to get the display to come out right with the original XML file.
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    Showcase your music collection on the Web

  7. #7
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    I seem to have messed that one up. This should fix it:
    HTML Code:
    <xsl:template match="/">
    <xsl:for-each select="grant/Deadlines/anyType">
      <xsl:value-of select="." /><br/>
    </xsl:for-each>
    </xsl:template>

  8. #8
    $this->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Dec 2003
    Location
    Federal Way, Washington (USA)
    Posts
    1,524
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, Vinnie. I'm still a relative newbie to XML, so bear with me if this is a dumb question, but in this statement:

    Code:
    <xsl:value-of select="." /><br/>
    is the "." saying to display anything between those tags? And is that what causes the multiple values to be printed with the line break between? I'm just trying to understand what makes this work. Thanks.
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    Showcase your music collection on the Web

  9. #9
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by vinyl-junkie
    Thanks, Vinnie. I'm still a relative newbie to XML, so bear with me if this is a dumb question, but in this statement:

    Code:
    <xsl:value-of select="." /><br/>
    is the "." saying to display anything between those tags? And is that what causes the multiple values to be printed with the line break between? I'm just trying to understand what makes this work. Thanks.
    The "." is the XPath expression for "this element". In our for-each tag above, we ask it to loop through all of the "anyType" tags it finds inside the "Deadlines" tag. It loops through each tag, writes out its contents thanks to the value-of tag, then adds a <br/> after it writes out the contents of anyType. You could also fix this up as an unordered list, which is probably what it's supposed to be anyway:
    HTML Code:
    <xsl:template match="/"> 
    <!--open the list up-->
    <ul>
    <xsl:for-each select="grant/Deadlines/anyType">  
    <!--fill list with items in anyType elements-->
    <li><xsl:value-of select="." /></li>
    </xsl:for-each> 
    <!--close the list-->
    </ul>
    </xsl:template>

  10. #10
    SitePoint Addict Brak's Avatar
    Join Date
    Jul 2004
    Location
    Central Coast, CA
    Posts
    321
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    nvm this.
    Studio Rockstar's Blog - A journey to quitting the dayjob.

  11. #11
    SitePoint Enthusiast revelstoke's Avatar
    Join Date
    Sep 2004
    Posts
    41
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I actually just replaced VGarcias '.' for "get the first element" with '*' for "get all children" and it worked perfectly.

    Regardless, this thread was extremely helpful in pointing me in the right direction. Even got a nice counter going now for my item list using <xsl:counter> -- rock on, thanks again guys.


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
  •