DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    benjamin Guest

    KEYWORD MAY NOT BE USED HERE ERRORS


    Hi,I've been learning XSLT and i keep getting "Keyword Cannot be used here
    Errors".
    PROBLEM NUMBER ONE:
    When i open the xml document on I.E version 5.0 i get this error
    "Keyword xsl:template may not be used here. "

    Is there anyone who can help me with this error?


    XML-CODE
    <?xml version="1.0" ?>
    <?xml:stylesheet type="text/xsl" href="Authors.xsl"?>
    <Publisher>

    <Item Itemtype="Hardcover" BookID="1" Sale="yes">
    <Category>Vegetables</Category>
    <ItemTitle>Cooking with Peppers</ItemTitle>
    <AuthorSet>
    <Author>
    <FirstName>Joe</FirstName>
    <LastName>Scarpella</LastName>
    </Author>
    <Author>
    <FirstName>Margaret</FirstName>
    <LastName>Smithson</LastName>
    </Author>
    </AuthorSet>
    </Item>

    <Item Itemtype="Hardcover" BookID="2" Sale="yes">
    <Category>Fruits</Category>
    <ItemTitle>Citrus from the World</ItemTitle>
    <AuthorSet>
    <Author>
    <FirstName>Maggie Mae</FirstName>
    <LastName>Suggins</LastName>
    </Author>
    <Author>
    <FirstName>Kharma</FirstName>
    <LastName>Apas</LastName>
    </Author>
    </AuthorSet>
    </Item>

    <Item Itemtype="Paperback" BookID="3">
    <Category>Fruits</Category>
    <ItemTitle>Apples of New England</ItemTitle>
    <AuthorSet>
    <Author>
    <FirstName>Carly</FirstName>
    <LastName>Montana</LastName>
    </Author>
    </AuthorSet>
    </Item>

    <Item Itemtype="Paperback" BookID="3">
    <Category>Vegetables</Category>
    <ItemTitle>Green Beans: Your Body's Savior</ItemTitle>
    <AuthorSet>
    <Author>
    <FirstName>Derek</FirstName>
    <LastName>Jacobs</LastName>
    </Author>
    <Author>
    <FirstName>Stephen</FirstName>
    <LastName>Scirella</LastName>
    </Author>
    <Author>
    <FirstName>Daisy</FirstName>
    <LastName>Miller</LastName>
    </Author>
    </AuthorSet>
    </Item>

    <Item Itemtype="Hardcover" BookID="5" Sale="yes">
    <Category>Pears</Category>
    <ItemTitle>Pears for People</ItemTitle>
    <AuthorSet>
    <Author>
    <FirstName>Diane</FirstName>
    <LastName>Craig</LastName>
    </Author>
    </AuthorSet>
    </Item>

    </Publisher>


    XSLT-CODE USING THE ABOVE XML DOCUMENT-"Authors.xsl"

    <?xml version="1.0"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl" version="1.0">
    <xsl:template match="/">
    <html>
    <head><title>Authors</title></head>
    <body>
    <h1>Authors</h1>
    <xsl:for-each select="//Item/AuthorSet">
    <xsl:apply-templates select ="Author"/>
    </xsl:for-each>

    <xsl:template match="Author">
    <xsl:value-of select="FirstName"/>&#x20;
    <xsl:value-of select="LastName"/>
    <xsl:choose>
    <xsl:when test="position() != last()">
    <xsl:text>,</xsl:text>
    </xsl:when>
    <xsltherwise>
    <br/>
    </xsltherwise>
    </xsl:choose>
    </xsl:template>



    </body>
    </html>
    </xsl:template>
    </xsl:stylesheet>

  2. #2
    Michael Guest

    Re: KEYWORD MAY NOT BE USED HERE ERRORS

    Benjamin,
    First add some debug code so you get a line number and better details. I'm
    not a master at XSLT but have been using it lately in some web sites and web
    apps I've been working on. Pretty cool stuff.

    1 problem is probably the fact that your using a MATCH attribute in your
    apply-templates syntax. Apply-templates directs the XSLT processor to find
    the appropriate template to apply, based on the type and context of each
    selected node. The only attributes available are SELECT and MODE which I
    doubt you need here.
    You only need <xsl:apply-template/> It applies the templates in order with
    the nodes in your XML doc. (As mentioned above.)

    I suggest moving your FOR-EACH loop into <xsl:template match="Item"> and
    inside your root template add <xsl:apply-templates/>. Do the same for you
    last template.

    If this isn't clear enough or your still having problems let me know. I can
    write out the code for you.
    For more details go to,
    http://msdn.microsoft.com/library/de...d_ref_8nas.asp
    Good luck!
    --

    Michael A Sanchez
    Runtime Web Development
    Dynamic Websites
    Business Applications
    Web: http://www.RuntimeWebDev.com
    eMail: MSanchez@RuntimeWebDev.com



    "benjamin" <benjamin@technobrainkenya.info> wrote in message
    news:3eed5fc9$1@tnews.web.devx.com...
    >
    > Hi,I've been learning XSLT and i keep getting "Keyword Cannot be used here
    > Errors".
    > PROBLEM NUMBER ONE:
    > When i open the xml document on I.E version 5.0 i get this error
    > "Keyword xsl:template may not be used here. "
    >
    > Is there anyone who can help me with this error?
    >
    >
    > XML-CODE
    > <?xml version="1.0" ?>
    > <?xml:stylesheet type="text/xsl" href="Authors.xsl"?>
    > <Publisher>
    >
    > <Item Itemtype="Hardcover" BookID="1" Sale="yes">
    > <Category>Vegetables</Category>
    > <ItemTitle>Cooking with Peppers</ItemTitle>
    > <AuthorSet>
    > <Author>
    > <FirstName>Joe</FirstName>
    > <LastName>Scarpella</LastName>
    > </Author>
    > <Author>
    > <FirstName>Margaret</FirstName>
    > <LastName>Smithson</LastName>
    > </Author>
    > </AuthorSet>
    > </Item>
    >
    > <Item Itemtype="Hardcover" BookID="2" Sale="yes">
    > <Category>Fruits</Category>
    > <ItemTitle>Citrus from the World</ItemTitle>
    > <AuthorSet>
    > <Author>
    > <FirstName>Maggie Mae</FirstName>
    > <LastName>Suggins</LastName>
    > </Author>
    > <Author>
    > <FirstName>Kharma</FirstName>
    > <LastName>Apas</LastName>
    > </Author>
    > </AuthorSet>
    > </Item>
    >
    > <Item Itemtype="Paperback" BookID="3">
    > <Category>Fruits</Category>
    > <ItemTitle>Apples of New England</ItemTitle>
    > <AuthorSet>
    > <Author>
    > <FirstName>Carly</FirstName>
    > <LastName>Montana</LastName>
    > </Author>
    > </AuthorSet>
    > </Item>
    >
    > <Item Itemtype="Paperback" BookID="3">
    > <Category>Vegetables</Category>
    > <ItemTitle>Green Beans: Your Body's Savior</ItemTitle>
    > <AuthorSet>
    > <Author>
    > <FirstName>Derek</FirstName>
    > <LastName>Jacobs</LastName>
    > </Author>
    > <Author>
    > <FirstName>Stephen</FirstName>
    > <LastName>Scirella</LastName>
    > </Author>
    > <Author>
    > <FirstName>Daisy</FirstName>
    > <LastName>Miller</LastName>
    > </Author>
    > </AuthorSet>
    > </Item>
    >
    > <Item Itemtype="Hardcover" BookID="5" Sale="yes">
    > <Category>Pears</Category>
    > <ItemTitle>Pears for People</ItemTitle>
    > <AuthorSet>
    > <Author>
    > <FirstName>Diane</FirstName>
    > <LastName>Craig</LastName>
    > </Author>
    > </AuthorSet>
    > </Item>
    >
    > </Publisher>
    >
    >
    > XSLT-CODE USING THE ABOVE XML DOCUMENT-"Authors.xsl"
    >
    > <?xml version="1.0"?>
    > <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl" version="1.0">
    > <xsl:template match="/">
    > <html>
    > <head><title>Authors</title></head>
    > <body>
    > <h1>Authors</h1>
    > <xsl:for-each select="//Item/AuthorSet">
    > <xsl:apply-templates select ="Author"/>
    > </xsl:for-each>
    >
    > <xsl:template match="Author">
    > <xsl:value-of select="FirstName"/>&#x20;
    > <xsl:value-of select="LastName"/>
    > <xsl:choose>
    > <xsl:when test="position() != last()">
    > <xsl:text>,</xsl:text>
    > </xsl:when>
    > <xsltherwise>
    > <br/>
    > </xsltherwise>
    > </xsl:choose>
    > </xsl:template>
    >
    >
    >
    > </body>
    > </html>
    > </xsl:template>
    > </xsl:stylesheet>




Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links