|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
xsl within xml file
can an xsl template be within the xml file or does it have to be an external file?
|
|
#2
|
|||
|
|||
|
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>
|
|
#3
|
|||
|
|||
|
I read somewhere that embeded stylesheets don't work in IE 6. Is this true?
|
|
#4
|
|||
|
|||
|
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. |
|
#5
|
|||
|
|||
|
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 |
|
#6
|
||||
|
||||
|
PHP Code:
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> |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > xsl within xml file |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|