Hi everyone!
I have got the following files "x.xml" and "x.xsl".
The x.xsl was supposed to transform the x.xml to show me a html in my brownser... I would show me the a page "paged" like "<<Prev 1 2 3 4 5 Next>>".
But when I open the x.xml in my brownser, the follow message appear:
The XML page cannot be displayed
Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.
Keyword xsl:script may not be used in namespace
Can somebody help me to solve this problem?
I there is no solution, can somebody send me a example of how to create a "paging" xsl???
Tks in advance!
cogubr@hotmail.com
Humberto
--------------------------------------------
x.xml
--------------------------------------------
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="x.xsl"?>
<series>
<page>
<title>Client-side Paging.</title>
<blerb>
<p>
I often get email asking me "How do I only display parts of a page
on the client." or "How do I page through some XML on the client".
</p>
<p>
I am going to use this tutorial as an example. If you look at the
<a href="Javascript:sourceWindow('slider.xml_')">XML</a> you will see many pages in the series but only
the first one (this page) is displayed.
</p>
<p>
This is achieved by passing a parameter to the stylesheet
<code><xsl
aram name="pagenumber" select="1" /></code>
then at the top level only applying templates to the parts you
want displayed i.e.
<code><xsl:apply-templates select="page[$pagenumber]" /></code>
I have set the parameter to 1 (select="1"
which instructs the
XSLT processor to use 1 if no parameter is passed to the stylesheet.
So the first time this XML is opened
the first page is displayed. See section x on how to change
this. You could change this manualy in the stylesheet to
display any page when the XML is opened.
</p>
</blerb>
</page>
<page>
<title>Displaying Page Links</title>
<blerb>
<p>
You will often want to add links to pages at the foot of
your page as is done in most of the search engines on the web.
</p>
<p>
This can't be done simply with an <xsl:apply-templates />
unless you want to get into modes. An <xsl:call-template />
to <a href="footerpagestemplate1.xsl">footerPages</a> is used
from the <a href="seriestemplate1.xsl">series</a> template.
</p>
<p>
As you can see from the template 2 parameters are
passed "pagenumber" and "element". The "pagenumber" parameter is
obvious it is the page currently being displayed. The "element"
parameter is the name of the element that is being paged in
this case I am using "page" although it could be any repeating
element that you want paged.
</p>
<p>
The output of this template is
<code> </code>
</p>
</blerb>
</page>
<page>
<title>Changing Pages</title>
<blerb>
<p>
You can see from the <a href="footerpagestemplate1.xsl">footerPages</a>
template that it uses an anchor to change the page.
This would be ok if it pointed to some server CGI which served up
the next page i.e.
<code><a href="slider.asp?pagenumber=8">8</a></code>
But we are trying to do this client-side.
</p>
<p>
There are 2 solutions to this the first is to have the anchor point
to a JavaScript function
which will reprocess the XML passing in the "pagenumber" parameter.
So you can add either this
<code><a href="JavaScript:changePage({$pagenumber +1});">Next</a></code>
or this
<code><a><br/>
<xsl:attribute name="href">JavaScript:changePage(<xsl:value-of select="$pagenumber+1" />);<xsl:attribute><br />
Next</a>
</code>
to the template.
Here is the resulting <a href="footerpagestemplate1.xsl">footerPages</a>
template.
</p>
</blerb>
</page>
<page>
<title>The JavaScript</title>
<blerb>
<p>
The JavaScript is included into the HTML by the top level
<a href="seriestemplate2.xsl">series</a> template. Clicking on the "Prev",
"Next" or number links causes the changePage function to be called with
the pagenumber passed as a parameter.
</p>
<p>
When you load an XML document with an associated stylesheet into IE
the properties document.XMLDocument and XSLDocument are available and
they point to the parsed XML and XSL DOM objects. These can be used
to reprocess the document. Here is some pseudo code on how to do it.
<code><pre>
function changePage(number){
var x = document.XMLDocument;
var s = document.XSLDocument;
s.addParameter("pagenumber", number);
var html = x.transformNode(s);
document.write(html);
}</pre>
</code>
The <a href="slider.js_">actual code</a> isn't much longer than this.
The main difference being that a processor needs to be created so that
you can add the "pagenumber" parameter. Also because the XML document
has been replaced with HTML the XMLDocument XSLDocument are stored
in the navigator object.
</p>
</blerb>
</page>
<page>
<title>The Final Stylesheet</title>
<blerb>
<p>
The <a href="Javascript:showSource('slider.xsl');">stylesheet</a>
just needs a couple of other templates to bring it all
together and display this tutorial.
</p>
</blerb>
</page>
</series>
--------------------------------------
x.xsl
--------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl=" <xsl
aram name="pagenumber" select="1" />
<xsl:template match="*|@*">
<xsl:copy>
<xsl:apply-templates select="@* | * | comment() | processing-instruction() | text()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="series">
<html>
<head>
<link rel="stylesheet" type="text/css" href="slider.css" />
<script language="javascript" src="slider.js" />
</head>
<body>
<xsl:if test="1=0">
<h1 style="color:red;">You need to be in "replace" mode to run this!!! <a href=" here</a></h1>
</xsl:if>
<xsl:apply-templates select="page[$pagenumber]" />
<div class="blerb">
<xsl:call-template name="footerPages">
<xsl:with-param name="element" select="'page'" />
<xsl:with-param name="pagenumber" select="$pagenumber" />
</xsl:call-template>
</div>
</body>
</html>
</xsl:template>
<xsl:template match="page">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="title">
<h1><xsl:value-of select="." /></h1>
</xsl:template>
<xsl:template match="blerb">
<div class="blerb">
<xsl:apply-templates />
</div>
</xsl:template>
<xsl:template match="p">
<p> <xsl:apply-templates /></p>
</xsl:template>
<xsl:template match="code">
<div class="code"><xsl:apply-templates /></div>
</xsl:template>
<xsl:template name="footerPages">
<xsl
aram name="element" />
<xsl
aram name="pagenumber" />
<xsl:variable name="total" select="count(*[name() = $element])" />
<center>
<xsl:if test="$pagenumber > 1">
<a href="JavaScript:changePage({$pagenumber -1});">Prev</a>
</xsl:if>
<xsl:for-each select="*[name() = $element]">
<xsl:choose>
<xsl:when test="not(count(preceding-sibling::*)+1 = $pagenumber)">
<a href="JavaScript:changePage({count(preceding-sibling::*)+1});"><xsl:value-of select="count(preceding-sibling::*)+1" /></a>
</xsl:when>
<xsl
therwise>
<xsl:value-of select="count(preceding-sibling::*)+1" />
</xsl
therwise>
</xsl:choose>
</xsl:for-each>
<xsl:if test="$pagenumber < $total">
<a href="JavaScript:changePage({$pagenumber +1});">Next</a>
</xsl:if>
</center>
</xsl:template>
<xsl:script><![CDATA[
function changePage(number){
try{
var s = new ActiveXObject("MSXML2.FreeThreadedDOMDocument"
;
var x = document.XMLDocument;
if (x == null){
x = navigator.XMLDocument;
s.loadXML(navigator.XSLDocument.xml);
}else{
s.loadXML(document.XSLDocument.xml);
}
var tem = new ActiveXObject("MSXML2.XSLTemplate"
;
tem.stylesheet = s;
var proc = tem.createProcessor();
proc.addParameter("pagenumber", number);
proc.input = x;
proc.transform();
var str = proc.output;
var newDoc = document.open("text/html", "replace"
;
newDoc.write(str);
navigator.XMLDocument = x;
navigator.XSLDocument = s;
newDoc.close();
}catch(exception){
}
}
]]></xsl:script>
</xsl:stylesheet>
I have got the following files "x.xml" and "x.xsl".
The x.xsl was supposed to transform the x.xml to show me a html in my brownser... I would show me the a page "paged" like "<<Prev 1 2 3 4 5 Next>>".
But when I open the x.xml in my brownser, the follow message appear:
The XML page cannot be displayed
Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.
Keyword xsl:script may not be used in namespace
Can somebody help me to solve this problem?
I there is no solution, can somebody send me a example of how to create a "paging" xsl???
Tks in advance!
cogubr@hotmail.com
Humberto
--------------------------------------------
x.xml
--------------------------------------------
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="x.xsl"?>
<series>
<page>
<title>Client-side Paging.</title>
<blerb>
<p>
I often get email asking me "How do I only display parts of a page
on the client." or "How do I page through some XML on the client".
</p>
<p>
I am going to use this tutorial as an example. If you look at the
<a href="Javascript:sourceWindow('slider.xml_')">XML</a> you will see many pages in the series but only
the first one (this page) is displayed.
</p>
<p>
This is achieved by passing a parameter to the stylesheet
<code><xsl
then at the top level only applying templates to the parts you
want displayed i.e.
<code><xsl:apply-templates select="page[$pagenumber]" /></code>
I have set the parameter to 1 (select="1"
XSLT processor to use 1 if no parameter is passed to the stylesheet.
So the first time this XML is opened
the first page is displayed. See section x on how to change
this. You could change this manualy in the stylesheet to
display any page when the XML is opened.
</p>
</blerb>
</page>
<page>
<title>Displaying Page Links</title>
<blerb>
<p>
You will often want to add links to pages at the foot of
your page as is done in most of the search engines on the web.
</p>
<p>
This can't be done simply with an <xsl:apply-templates />
unless you want to get into modes. An <xsl:call-template />
to <a href="footerpagestemplate1.xsl">footerPages</a> is used
from the <a href="seriestemplate1.xsl">series</a> template.
</p>
<p>
As you can see from the template 2 parameters are
passed "pagenumber" and "element". The "pagenumber" parameter is
obvious it is the page currently being displayed. The "element"
parameter is the name of the element that is being paged in
this case I am using "page" although it could be any repeating
element that you want paged.
</p>
<p>
The output of this template is
<code> </code>
</p>
</blerb>
</page>
<page>
<title>Changing Pages</title>
<blerb>
<p>
You can see from the <a href="footerpagestemplate1.xsl">footerPages</a>
template that it uses an anchor to change the page.
This would be ok if it pointed to some server CGI which served up
the next page i.e.
<code><a href="slider.asp?pagenumber=8">8</a></code>
But we are trying to do this client-side.
</p>
<p>
There are 2 solutions to this the first is to have the anchor point
to a JavaScript function
which will reprocess the XML passing in the "pagenumber" parameter.
So you can add either this
<code><a href="JavaScript:changePage({$pagenumber +1});">Next</a></code>
or this
<code><a><br/>
<xsl:attribute name="href">JavaScript:changePage(<xsl:value-of select="$pagenumber+1" />);<xsl:attribute><br />
Next</a>
</code>
to the template.
Here is the resulting <a href="footerpagestemplate1.xsl">footerPages</a>
template.
</p>
</blerb>
</page>
<page>
<title>The JavaScript</title>
<blerb>
<p>
The JavaScript is included into the HTML by the top level
<a href="seriestemplate2.xsl">series</a> template. Clicking on the "Prev",
"Next" or number links causes the changePage function to be called with
the pagenumber passed as a parameter.
</p>
<p>
When you load an XML document with an associated stylesheet into IE
the properties document.XMLDocument and XSLDocument are available and
they point to the parsed XML and XSL DOM objects. These can be used
to reprocess the document. Here is some pseudo code on how to do it.
<code><pre>
function changePage(number){
var x = document.XMLDocument;
var s = document.XSLDocument;
s.addParameter("pagenumber", number);
var html = x.transformNode(s);
document.write(html);
}</pre>
</code>
The <a href="slider.js_">actual code</a> isn't much longer than this.
The main difference being that a processor needs to be created so that
you can add the "pagenumber" parameter. Also because the XML document
has been replaced with HTML the XMLDocument XSLDocument are stored
in the navigator object.
</p>
</blerb>
</page>
<page>
<title>The Final Stylesheet</title>
<blerb>
<p>
The <a href="Javascript:showSource('slider.xsl');">stylesheet</a>
just needs a couple of other templates to bring it all
together and display this tutorial.
</p>
</blerb>
</page>
</series>
--------------------------------------
x.xsl
--------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl=" <xsl
<xsl:template match="*|@*">
<xsl:copy>
<xsl:apply-templates select="@* | * | comment() | processing-instruction() | text()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="series">
<html>
<head>
<link rel="stylesheet" type="text/css" href="slider.css" />
<script language="javascript" src="slider.js" />
</head>
<body>
<xsl:if test="1=0">
<h1 style="color:red;">You need to be in "replace" mode to run this!!! <a href=" here</a></h1>
</xsl:if>
<xsl:apply-templates select="page[$pagenumber]" />
<div class="blerb">
<xsl:call-template name="footerPages">
<xsl:with-param name="element" select="'page'" />
<xsl:with-param name="pagenumber" select="$pagenumber" />
</xsl:call-template>
</div>
</body>
</html>
</xsl:template>
<xsl:template match="page">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="title">
<h1><xsl:value-of select="." /></h1>
</xsl:template>
<xsl:template match="blerb">
<div class="blerb">
<xsl:apply-templates />
</div>
</xsl:template>
<xsl:template match="p">
<p> <xsl:apply-templates /></p>
</xsl:template>
<xsl:template match="code">
<div class="code"><xsl:apply-templates /></div>
</xsl:template>
<xsl:template name="footerPages">
<xsl
<xsl
<xsl:variable name="total" select="count(*[name() = $element])" />
<center>
<xsl:if test="$pagenumber > 1">
<a href="JavaScript:changePage({$pagenumber -1});">Prev</a>
</xsl:if>
<xsl:for-each select="*[name() = $element]">
<xsl:choose>
<xsl:when test="not(count(preceding-sibling::*)+1 = $pagenumber)">
<a href="JavaScript:changePage({count(preceding-sibling::*)+1});"><xsl:value-of select="count(preceding-sibling::*)+1" /></a>
</xsl:when>
<xsl
<xsl:value-of select="count(preceding-sibling::*)+1" />
</xsl
</xsl:choose>
</xsl:for-each>
<xsl:if test="$pagenumber < $total">
<a href="JavaScript:changePage({$pagenumber +1});">Next</a>
</xsl:if>
</center>
</xsl:template>
<xsl:script><![CDATA[
function changePage(number){
try{
var s = new ActiveXObject("MSXML2.FreeThreadedDOMDocument"
var x = document.XMLDocument;
if (x == null){
x = navigator.XMLDocument;
s.loadXML(navigator.XSLDocument.xml);
}else{
s.loadXML(document.XSLDocument.xml);
}
var tem = new ActiveXObject("MSXML2.XSLTemplate"
tem.stylesheet = s;
var proc = tem.createProcessor();
proc.addParameter("pagenumber", number);
proc.input = x;
proc.transform();
var str = proc.output;
var newDoc = document.open("text/html", "replace"
newDoc.write(str);
navigator.XMLDocument = x;
navigator.XSLDocument = s;
newDoc.close();
}catch(exception){
}
}
]]></xsl:script>
</xsl:stylesheet>