I have made use of xsl:when to display my details. The details which I need to display is a title of the book. Now I want to display the title with one change. If the title is 'Cpp.....' I need to replace it with 'C++....' and display that book with this title in the browser. This is to be incorporated for all books which have Cpp in their title.
I have edited my quesition. Can you help me with this?
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" exclude-result-prefixes="rdf rss"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:rss="http://my.netscape.com/rdf/simple/0.9/"
xmlns:kb="http://protege.stanford.edu/kb#">
<xsl:output method="html" indent="yes" />
<xsl:template match="wt:sparql/wt:results/wt:result"
xmlns:wt="http://www.w3.org/2005/sparql-results#">
<script type="text/javascript"></script>
<h3>
<xsl:choose>
<xsl:when test="wt:binding[@name='count']/wt:literal <= 5">
<a style="color:red">
<xsl:attribute name="onclick">
prepareEditValue('<xsl:value-of select="wt:binding[@name='x']/wt:uri"></xsl:value-of>', false);
</xsl:attribute>
<xsl:value-of select="wt:binding[@name='title']/wt:literal" />
</a>
</xsl:when>
<xsl:when test="wt:binding[@name='count']/wt:literal <= 50">
<a style="color:blue">
<xsl:attribute name="onclick">
prepareEditValue('<xsl:value-of select="wt:binding[@name='x']/wt:uri"></xsl:value-of>', false);
</xsl:attribute>
<xsl:value-of select="wt:binding[@name='title']/wt:literal" />
</a>
</xsl:when>
<xsl:otherwise>
<a>
<xsl:attribute name="onclick">
prepareEditValue('<xsl:value-of select="wt:binding[@name='x']/wt:uri"></xsl:value-of>', false);
</xsl:attribute>
<xsl:value-of select="wt:binding[@name='title']/wt:literal" />
</a>
</xsl:otherwise>
</xsl:choose>
</h3>
<div>
<xsl:value-of select="wt:binding[@name='description']/wt:literal" /> Price:
<xsl:value-of select="wt:binding[@name='price']/wt:literal" />
<xsl:value-of select="wt:binding[@name='currency']/wt:literal" />
<div style="float:right;">
<input type="button" value="Edit">
<xsl:attribute name="onclick">
prepareEditValue('<xsl:value-of select="wt:binding[@name='x']/wt:uri"></xsl:value-of>', true);
</xsl:attribute>
</input>
<input type="button" value="Delete">
<xsl:attribute name="onclick">
deleteBookDialog('<xsl:value-of select="wt:binding[@name='x']/wt:uri"></xsl:value-of>');
</xsl:attribute>
</input>
</div>
</div>
</xsl:template>
</xsl:stylesheet>
The rdf file which has the data is
Welcome to C yy $ 8 8
Cpp Primer Plus Stephen Prata € 36.94 88
<rdf:Description rdf:about="http://protege.stanford.edu/kb#Linux Programming Bible">
<kb:Title>Linux Programming Bible</kb:Title>
<kb:Author>John Goerzen</kb:Author>
<kb:Currency>$</kb:Currency>
<kb:Price>77</kb:Price>
<kb:Count>34</kb:Count>
</rdf:Description>
<rdf:Description rdf:about="http://protege.stanford.edu/kb#CSharp-The Basics">
<kb:Title>CSharp-The Basics</kb:Title>
<kb:Author>Vijay Mukhi</kb:Author>
<kb:Currency>€</kb:Currency>
<kb:Price>56</kb:Price>
<kb:Count>6</kb:Count>
</rdf:Description>
<rdf:Description rdf:about="http://protege.stanford.edu/kb#Cpp Primer Answer Book">
<kb:Title>Cpp Primer Answer Book</kb:Title>
<kb:Author>Clovis L.Tondo</kb:Author>
<kb:Currency>$</kb:Currency>
<kb:Price>24.40</kb:Price>
<kb:Count>100</kb:Count>
</rdf:Description>
<rdf:Description rdf:about="http://protege.stanford.edu/kb#Ajax for Dummies">
<kb:Title>Ajax for Dummies</kb:Title>
<kb:Author>Steve Holzner</kb:Author>
<kb:Currency>$</kb:Currency>
<kb:Price>21.89</kb:Price>
<kb:Count>3</kb:Count>
</rdf:Description>
<rdf:Description rdf:about="http://protege.stanford.edu/kb#Beginning Programming with
Cpp For Dummies">
<kb:Title>Beginning Programming with Cpp For Dummies</kb:Title>
<kb:Author>Stephen R.Davis</kb:Author>
<kb:Currency>$</kb:Currency>
<kb:Price>19.69</kb:Price>
<kb:Count>99</kb:Count>
</rdf:Description>
<rdf:Description rdf:about="http://protege.stanford.edu/kb#Programming in ANSI C">
<kb:Title>Programming in ANSI C</kb:Title>
<kb:Author>Stephen G.Kochan</kb:Author>
<kb:Currency>$</kb:Currency>
<kb:Price>99</kb:Price>
<kb:Count>9</kb:Count>
</rdf:Description>
<rdf:Description rdf:about="http://protege.stanford.edu/kb#Introduction to Programming
Using Java">
<kb:Title>Introduction to Programming Using Java</kb:Title>
<kb:Author>David J.Eck</kb:Author>
<kb:Currency>$</kb:Currency>
<kb:Price>89</kb:Price>
<kb:Count>23</kb:Count>
</rdf:Description>
<rdf:Description rdf:about="http://protege.stanford.edu/kb#Crafting a Compiler with C">
<kb:Title>Crafting a Compiler with C</kb:Title>
<kb:Author>Charles N.Fischer</kb:Author>
<kb:Currency>$</kb:Currency>
<kb:Price>95</kb:Price>
<kb:Count>8</kb:Count>
</rdf:Description>
<rdf:Description rdf:about="http://protege.stanford.edu/kb#Sams Teach Yourself C Sharp
in 24 Hours">
<kb:Title>Sams Teach Yourself C Sharp in 24 Hours</kb:Title>
<kb:Author>Sams</kb:Author>
<kb:Currency>$</kb:Currency>
<kb:Price>89</kb:Price>
<kb:Count>9</kb:Count>
</rdf:Description>
<rdf:Description rdf:about="http开发者_如何学Python://protege.stanford.edu/kb#Compiler Constructions">
<kb:Title>Compiler Constructions</kb:Title>
<kb:Author>Jeremy Perk</kb:Author>
<kb:Currency>$</kb:Currency>
<kb:Price>88</kb:Price>
<kb:Count>9</kb:Count>
</rdf:Description>
<rdf:Description rdf:about="http://protege.stanford.edu/kb#Real Time Concepts for
Embedded Systems">
<kb:Title>Real Time Concepts for Embedded Systems</kb:Title>
<kb:Author>Qing Li</kb:Author>
<kb:Currency>€</kb:Currency>
<kb:Price>109</kb:Price>
<kb:Count>88</kb:Count>
</rdf:Description>
<rdf:Description rdf:about="http://protege.stanford.edu/kb#Introduction to Algorithms">
<kb:Title>Introduction to Algorithms</kb:Title>
<kb:Author>Thomas Cormen</kb:Author>
<kb:Currency>$</kb:Currency>
<kb:Price>33</kb:Price>
<kb:Count>6</kb:Count>
</rdf:Description>
<rdf:Description rdf:about="http://protege.stanford.edu/kb#Begineer to Cpp ">
<kb:Count>7</kb:Count>
<kb:Price>77</kb:Price>
<kb:Currency>$</kb:Currency>
<kb:Author>Harry</kb:Author>
<kb:Title>Begineer to Cpp </kb:Title>
</rdf:Description>
</rdf:RDF>
Archana.
You can try something like this..
<xsl:if test="@title">
<xsl:variable name="CPP">Cpp</xsl:variable>
<xsl:when test="contains(@Title, $CPP)">
<xsl:value-of select="replace(@title,'.cpp','')"/>
<xsl:text>C++</xsl:text>
</xsl:when>
<xsl:othersise>
<xsl:value-of select="@title"/>
</xsl:othersise>
</xsl:if>
It checks for a title attribute. If exists, compares it to value of variable CPP
. If matches then prints our "C++".
精彩评论