XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 19th, 2004, 10:34 PM
batookee batookee is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Posts: 30 batookee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 33 m 20 sec
Reputation Power: 7
xsl within xml file

can an xsl template be within the xml file or does it have to be an external file?

Reply With Quote
  #2  
Old September 22nd, 2004, 05:17 AM
fpmurphy fpmurphy is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Location: USA
Posts: 305 fpmurphy User rank is Corporal (100 - 500 Reputation Level)fpmurphy User rank is Corporal (100 - 500 Reputation Level)fpmurphy User rank is Corporal (100 - 500 Reputation Level)fpmurphy User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 1 Day 7 h 17 m 54 sec
Reputation Power: 7
Yes, you can do so. It is called an embedded stylesheet. For the gory details (and an example) see:

http://www.w3.org/TR/xslt.html#section-Embedding-Stylesheets

Here is an example that works with most browsers.

Code:
<?xml version="1.0"?>
<?xml-stylesheet href="#getItHere" type="text/xsl"?>

<!DOCTYPE children [
<!ATTLIST xsl:stylesheet
   id        ID    #REQUIRED
   xmlns:xsl CDATA #FIXED "http://www.w3.org/1999/XSL/Transform"
   version   CDATA #FIXED "1.0">
]>

<children>

<xsl:stylesheet  version="1.0" id="getItHere"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
<html>
   <head>
       <title>Names of my children</title>
   </head>
   <body>
       <h1><center>My Children's Names</center></h1>
       <ul>
          <xsl:apply-templates select="/children/child"/>
       </ul>
   </body>
</html>
</xsl:template>

<xsl:template match="/children/child">
         <li><xsl:value-of select="."/></li>
</xsl:template>

</xsl:stylesheet>

   <child>Ciara</child>
   <child>Kenneth</child>
</children>

Reply With Quote
  #3  
Old September 22nd, 2004, 06:09 AM
batookee batookee is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Posts: 30 batookee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 33 m 20 sec
Reputation Power: 7
I read somewhere that embeded stylesheets don't work in IE 6. Is this true?

Reply With Quote
  #4  
Old September 23rd, 2004, 09:00 PM
fpmurphy fpmurphy is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Location: USA
Posts: 305 fpmurphy User rank is Corporal (100 - 500 Reputation Level)fpmurphy User rank is Corporal (100 - 500 Reputation Level)fpmurphy User rank is Corporal (100 - 500 Reputation Level)fpmurphy User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 1 Day 7 h 17 m 54 sec
Reputation Power: 7
Yes and no. The sample code I provided partially works
with IE6 (try it with IE6 and FireFox) and would probably
work if I spent the time to figure out what is going on.

Reply With Quote
  #5  
Old September 25th, 2004, 10:01 PM
batookee batookee is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Posts: 30 batookee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 33 m 20 sec
Reputation Power: 7
Question

Hi,
Yeah the code you gave me works but when I tryied to intergrate it with my own code... god only knows what happened. (Can you tell I don't know a whole lot about this)

Maybe you can point me in the right direction


Here's my XSL sheet, its pretty simple:
Code:
<?xml version="1.0" encoding="ISO-8859-1"?><xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="/">
<html> 
<body> 
<xsl:for-each select="collection/artist"> 
	<xsl:value-of select="@name"/>
<xsl:for-each select="album">
<ul><li>
   <xsl:value-of select="." />
</li></ul>
</xsl:for-each>
</xsl:for-each> 
</body>
</html>
</xsl:template>
</xsl:stylesheet>


And here's what my XML looks like
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="simple.xsl" ?>
<collection>
<artist name="AC/DC">
<album>74 Jailbreak</album>
<album>Back In Black</album>
</artist>
<artist name="Aerosmith">
<album>Honkin' On Bobo</album>
<album>Young Lust-The Aerosmith Anthology</album>
</artist>
<artist name="Bachman Turner Overdrive">
<album>Not Fragile</album>
</artist>
.
.
.
.
.
</collection>

Can you possibly help me put them together, I'd appreciate it.

Thanks

Reply With Quote
  #6  
Old September 27th, 2004, 01:19 PM
Teflon's Avatar
Teflon Teflon is offline
Teflon The Black
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Location: Woodbridge VA
Posts: 246 Teflon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 28 m 14 sec
Reputation Power: 5
Send a message via AIM to Teflon
Thumbs up

PHP Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml
-stylesheet type="text/xsl" href="#stylesheet"?>
<!DOCTYPE doc [
<!ATTLIST xsl:stylesheet
id ID #REQUIRED>
]>
<collection>
<xsl:stylesheet version="1.0" id="stylesheet" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html"/>
    <xsl:template match="/">
        <html>
            <body>
                <xsl:for-each select="collection/artist">
                    <xsl:value-of select="@name"/>
                    <xsl:for-each select="album">
                        <ul><li>
                           <xsl:value-of select="." />
                        </li></ul>
                    </xsl:for-each>
                </xsl:for-each>
            </body>
        </html>
        </xsl:template>
</xsl:stylesheet>

    <artist name="AC/DC">
        <album>74 Jailbreak</album>
        <album>Back In Black</album>
    </artist>
    <artist name="Aerosmith">
        <album>Honkin' On Bobo</album>
        <album>Young Lust-The Aerosmith Anthology</album>
    </artist>
    <artist name="Bachman Turner Overdrive">
        <album>Not Fragile</album>
    </artist>
</collection>


Looks like the main thing missing was the <xsl:output method="html"/> part :D

Of course IE6 is havin some issues with it but it looks great in FIREFOX
__________________
Teflon - The Black <desc>Mark This Up</desc>

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > xsl within xml file


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT