i'm having issue xml not showing correctly. basically, have xml document full of links , want xsl stylesheet output xml in ordered list. far, working right , styling correct, no data showing links. see stylized background. connected xml correctly xsl , dreamweaver validated xml code without hitch. not sure i'm missing here?
test.xml
<?xml version="1.0" encoding="utf-8"?> <?xml-stylesheet type="text/xsl" href="teststyle.xsl"?> <country xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"> <au> <open><li><a href="/contest/test/goto.php?id=0" target="_blank"></open> <description>win macbook!</description> <close></a></li></close> </au> <au> <open><li><a href="/contest/test/goto.php?id=1" target="_blank"></open> <description>win trip las vegas!</description> <close></a></li></close> </au> </country>
teststyle.xsl
<?xml version="1.0" encoding="utf-8"?><!-- dwxmlsource="test.xml" --> <!doctype xsl:stylesheet [ <!entity nbsp " "> <!entity copy "©"> <!entity reg "®"> <!entity trade "™"> <!entity mdash "—"> <!entity ldquo "“"> <!entity rdquo "”"> <!entity pound "£"> <!entity yen "¥"> <!entity euro "€"> ]> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:output method="html" encoding="utf-8" doctype-public="-//w3c//dtd xhtml 1.0 transitional//en" doctype-system="http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"/> <xsl:template match="/"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"/> <title>untitled document</title> </head> <body style="font-family:arial;font-size:12pt;background-color:#eeeeee"> <xsl:for-each select="country/au"> <div style="background-color:teal;color:white;padding:4px"> <ol> <span style="font-weight:bold"><xsl:value-of select="country/au/open" /><xsl:value-of select="country/au/description"/><xsl:value-of select="country/au/close"/></span> </ol> </div> </xsl:for-each> </body> </html> </xsl:template> </xsl:stylesheet>
when have "for-each" block, instructions inside block relative element you're running them in. means instead of
<xsl:value-of select="country/au/open" />
you should use
<xsl:value-of select="open" />
also, assuming want < , > characters "open" , "close" blocks, need disable output escaping on links. otherwise you'll end escape codes in page.
here full, working version of xsl:
<?xml version="1.0" encoding="utf-8"?><!-- dwxmlsource="test.xml" --> <!doctype xsl:stylesheet [ <!entity nbsp " "> <!entity copy "©"> <!entity reg "®"> <!entity trade "™"> <!entity mdash "—"> <!entity ldquo "“"> <!entity rdquo "”"> <!entity pound "£"> <!entity yen "¥"> <!entity euro "€"> ]> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:output method="html" encoding="utf-8" doctype-public="-//w3c//dtd xhtml 1.0 transitional//en" doctype-system="http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"/> <xsl:template match="/"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"/> <title>untitled document</title> </head> <body style="font-family:arial;font-size:12pt;background-color:#eeeeee"> <xsl:for-each select="country/au"> <div style="background-color:teal;color:white;padding:4px"> <ol> <span style="font-weight:bold"><xsl:value-of select="open" disable-output-escaping="yes" /><xsl:value-of select="description"/><xsl:value-of select="close" disable-output-escaping="yes"/></span> </ol> </div> </xsl:for-each> </body> </html> </xsl:template> </xsl:stylesheet>
however, i'd recommend against putting escaped html code xml that. it's not clear what's happening, , there's lot of unnecessary mess involved in escaping characters. better figure out data need, , use xsl turn data valid html. example, if changed xml data file this:
<?xml version="1.0" encoding="utf-8"?> <?xml-stylesheet type="text/xsl" href="teststyle.xsl"?> <country xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"> <au> <url>/contest/test/goto.php?id=0</url> <target>_blank</target> <description>win macbook!</description> </au> <au> <url>/contest/test/goto.php?id=1</url> <target>_blank</target> <description>win trip las vegas!</description> </au> </country>
then xsl makes behavior bit clearer (and don't need handle escaping!):
<?xml version="1.0" encoding="utf-8"?><!-- dwxmlsource="test.xml" --> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:output method="html" encoding="utf-8" doctype-public="-//w3c//dtd xhtml 1.0 transitional//en" doctype-system="http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"/> <xsl:template match="/"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>untitled document</title> </head> <body style="font-family:arial;font-size:12pt;background-color:#eeeeee"> <xsl:for-each select="country/au"> <div style="background-color:teal;color:white;padding:4px"> <ol style="font-weight:bold"> <a href="{url}" target="{target}"><xsl:value-of select="description"/></a> </ol> </div> </xsl:for-each> </body> </html> </xsl:template> </xsl:stylesheet>
Comments
Post a Comment