View Full Version : Can xml, xquery, xslt do this?
I want to create a list of all the HTML tags and have each tag have its own page. In the page I want to have the tag the attributes it can have and some examples of how its used.
Could I create an xml document with all the tags and then have xquery get all the information inside the xml tag of the thml tag, then use xslt to display the information?
I think this is possible, but it just seems like I would need to use asp or php to do this. Am I missing something or can I do this?
hemebond
08-18-2005, 10:28 PM
Could I create an xml document with all the tags and then have xquery get all the information inside the xml tag of the thml tag, then use xslt to display the information?Yes..
mindlessLemming
08-19-2005, 03:35 AM
The html doctype contains exactly what you are talking about. If you're really keen, you could write an XSL stylesheet to transform the DTD into something easier to read... a word of caution though, if you need to ask if a server side language is required, understanding dtd's and transforming them with XSL is going to feel like a shotgun to the brain ;)
So I don't start a new topic.
Would anyone like to tell me why that if I would type this in an xml document <code><p></code> and then in the xsl document type <xsl:value-of select="code" /> nothing happens. But if I change the < > to the actual angled bracket symbols it shows <p> instead of creating a new paragraph. Did I do something wrong or is this how its suppose to be?
hemebond
08-19-2005, 07:33 AM
Need to see the rest of your code.
xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="tags.xsl"?>
<tags>
<tag>
<name id="a">a</name>
<attribute>
<type>href</type>
<value>URL</value>
</attribute>
<attribute>
<type>shape</type>
<value>circ</value>
<value>circle</value>
<value>rect</value>
<value>rectangle</value>
<value>poly</value>
<value>polygon</value>
</attribute>
<attribute>
<type>target</type>
<value>_blank</value>
<value>_parent</value>
<value>_self</value>
<value>_top</value>
</attribute>
<example>
<code><a href="URL">This is a link.</a></code>
<display><a href="URL">this is a link.</a><display>
</tag>
</tags>
xsl
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
<link rel="stylesheet" type="text/css" href="yahncss.css" />
<title>HTML tutorial</title>
</head>
<body>
<xsl:for-each select="tags/tag">
<h1 class="tut">The <<xsl:value-of select="name" />></h1>
<table border="1" cellpadding="2" cellspacing="0">
<tr>
<td>attribute</td>
<td>value</td>
</tr>
<xsl:for-each select="attribute">
<tr>
<td><xsl:value-of select="type" /></td>
<td>
<xsl:for-each select="value">
<xsl:value-of select="." /><br />
</xsl:for-each>
</td>
</tr>
</xsl:for-each>
</table>
<hr />
<table border="1" cellpadding="2" cellspacing="0">
<tr>
<td><xsl:value-of select="code" /></td>
</tr>
</table>
<hr />
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
hemebond
08-22-2005, 08:04 AM
66239.xml<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="66239.xsl"?>
<tags>
<tag>
<name>a</name>
<attribute>
<type>href</type>
<value>URL</value>
</attribute>
<attribute>
<type>shape</type>
<value>circ</value>
<value>circle</value>
<value>rect</value>
<value>rectangle</value>
<value>poly</value>
<value>polygon</value>
</attribute>
<attribute>
<type>target</type>
<value>_blank</value>
<value>_parent</value>
<value>_self</value>
<value>_top</value>
</attribute>
<example>
<source><![CDATA[<a href="URL">this is a link.</a>]]></source>
<result><a href="URL">this is a link.</a></result>
</example>
</tag>
</tags>66239.xsl<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
<link rel="stylesheet" type="text/css" href="yahncss.css" />
<title>HTML Tutorial</title>
</head>
<body>
<h1>HTML Tutorial</h1>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="tag">
<h2><xsl:attribute name="id"><xsl:value-of select="name"/></xsl:attribute>The <<xsl:value-of select="name"/>></h2>
<table border="1">
<thead>
<tr>
<th>attribute</th>
<th>value</th>
</tr>
</thead>
<tbody>
<xsl:apply-templates select="attribute"/>
</tbody>
</table>
<xsl:apply-templates select="example"/>
</xsl:template>
<xsl:template match="attribute">
<tr>
<td>
<xsl:value-of select="type"/>
</td>
<td>
<ul>
<xsl:apply-templates select="value"/>
</ul>
</td>
</tr>
</xsl:template>
<xsl:template match="value">
<li><xsl:apply-templates/></li>
</xsl:template>
<xsl:template match="example">
<dl>
<dt>Example</dt>
<dd>
<xsl:apply-templates select="source"/>
</dd>
<dd>
<xsl:apply-templates select="result"/>
</dd>
</dl>
</xsl:template>
<xsl:template match="source">
<pre style="border:1px solid #000">
<xsl:apply-templates/>
</pre>
</xsl:template>
<xsl:template match="result">
<pre style="border:1px solid #000">
<xsl:copy-of select="node()"/>
</pre>
</xsl:template>
</xsl:stylesheet>
ahh.. ok I saw the cdata code but I thought you could just use the & symbols. I guess I was wrong.
Anyways I have another page that lists just the name of the tags. I want when you click a link for it to bring the xml up for just that tag. I thought xquery would be what I needed, but I read the w3schools tutorial for it and it seems like I need something else. Do I need xquery or xlink or xsomethingelse? And do you know of a better tutorial for it then w3schools?
Thanks for all your help.
hemebond
08-22-2005, 10:33 PM
It would be very easy using server-side scripting.
well php can't work with xml can it? And my server doesn't host ASP, so I couldn't use the xml document with php could I?
hemebond
08-23-2005, 02:35 AM
http://php.planetmirror.com/manual/en/ref.simplexml.php
http://php.planetmirror.com/manual/en/ref.domxml.php
oo.. thank you. I read somewhere php can't handle xml, I guess that was wrong. Hmm.. This seems like it might take a while to get the hang of though. I guess everyone has to get started somewhere though. Thanks again for all your help.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.