Subject: Re: [xsl] Predicates question From: Chris Maloney <voldrani@xxxxxxxxx> Date: Sat, 17 Dec 2011 09:24:14 -0500 |
You have a couple of other syntax errors, too. You forgot to close your "<xsl:value-of..." elements with "/>". Try this: <?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">B <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> <xsl:template match="/">B B <xsl:apply-templates select="/bookstore/book[position()<3]" />B </xsl:template> <xsl:template match="bookstore/book">B B <h1><xsl:value-of select="title"/></h1>B B B <xsl:value-of select="price"/> </xsl:template>B B </xsl:stylesheet> On Sat, Dec 17, 2011 at 8:58 AM, Wolfgang Laun <wolfgang.laun@xxxxxxxxx> wrote: > > A basic requirement for writing XML (and XSLT is XML) is to represent > all '<' that are part of the data (element or attribute or other) as > < > > Another characters in the same category is '&', which must be written > as &. when it is a data character (and not part of a character > reference that begins with '&'). > > (You may also find '>' written as >.) > > There's also a construct known as CDATA section, which is a general > "escape" mechanism for element data. See /bookstore/book[2] for > details ;-) > > -W > > On 17 December 2011 14:39, Roelof Wobben <rwobben@xxxxxxxxxxx> wrote: > > > > > > I have this small xml file : > > > > > > > > <?xml version="1.0" encoding="ISO-8859-1"?> > > B <bookstore> > > > > B <book> > > B <title lang="eng">Harry Potter</title> > > B <price>29.99</price> > > B </book> > > > > B <book> > > B <title lang="eng">Learning XML</title> > > B <price>39.95</price> > > B </book> > > > > B </bookstore> > > > > > > > > And now I want to show only a few books. > > > > According to this page : http://www.w3schools.com/xpath/xpath_syntax.asp I can use this xslt : > > > > > > > > <?xml version="1.0" encoding="UTF-8"?> > > <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> > > B <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> > > > > <xsl:template match="/"> > > B <xsl:apply-templates select="/bookstore/book[position()<3]" /> > > </xsl:template> > > > > <xsl:template match="bookstore/book"> > > B <h1><xsl:value-of select="title"</h1> > > B <xsl:value-of select="price" > > </xsl:template> > > > > </xsl:stylesheet> > > > > > > But if I try this on xmlspy I get this message : > > > > > > > > Character '<' is grammatically unexpected > > B Reason: one of the following is expected (see below) > > B '"' > > B '&' > > B '&#' > > B '&#x' > > B [^<&"] > > B Details > > B XML production: Production 'AttValue' not satisfied > > > > > > > > What part did I misunderstood. > > > > > > > > Roelof
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Predicates question, Wolfgang Laun | Thread | RE: [xsl] Predicates question, Roelof Wobben |
Re: [xsl] Predicates question, Wolfgang Laun | Date | RE: [xsl] Predicates question, Roelof Wobben |
Month |