Hello everyone,
I'm fairly new to XML and XSLT, and am trying to use it's power as a web designer/developer. I have three files:
- markup.xml
- logic.xsl
- data.xml
I am trying to make the logic recognize every instance of the "resource" tag in the markup.xml. Once it does this it then uses the information to grab data from the data.xml file and output it to the viewer.
Here is the markup.xml:
Code:
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="logic.xsl"?>
<page>
<resource idc="page.content"/>
</page>
And here is the data.xml:
Code:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<res id="page.content">It Works!</res>
</resources>
I don't need to tell you both of these files are simple and straight forward. Now let's take a look at the logic.xslt:
Code:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:variable name="data" select="document('data.xml')/resources/res"/>
<xsl:template match="page">
<html>
<head>
<title>The Page</title>
</head>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="resource">
<xsl:param name="identity"><xsl:value-of select="@idc"/></xsl:param>
<xsl:apply-templates select="concat($data,'[@id='',$identity,'']')"/>
</xsl:template>
</xsl:stylesheet>
The logic.xsl first defines a variable needed to know where to look for the data every time the $data variable is used. Next it outputs the standard XHTML markup with a template. Near the bottom it matches all <resource> tags. This is where the magic is suppose to happen. In theory it would grab all the data, depending on the value of the <resource> attribute, from the selected element of the data.xml.
Again I am new to this so perhaps it's an obvious mistake I do not see. I am suspecting perhaps you can have document(concat()) but not concat(document()). If this is so please let me know.
Thank you so much for any and all help you can provide.