2011-04-05 5 views
-1

내 세부 정보를 표시 할 때 xsl :을 사용했습니다. 표시해야 할 세부 정보는 책 제목입니다. 이제 한 가지 변경 사항으로 제목을 표시하고 싶습니다. 제목이 'Cpp .....'인 경우 'C++ ....'으로 바꾸고이 제목으로 브라우저에 표시해야합니다. 제목에 Cpp이있는 모든 책에 적용됩니다.xsl의 사용 :

내 질문을 수정했습니다. 도와 드릴까요?

<?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 &lt;= 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 &lt;= 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> 

데이터가있는 RDF 파일은 C 전년 동기 대비 $

CPP 프라이머 플러스 스티븐 프라 타 â에

환영합니다 ¬.94

<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://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> 

아차 나 210.

+0

이미 가지고있는 코드의 예를 제공해 줄 수 있습니까? –

+0

이것은 나쁜 질문의 또 다른 예입니다. XML 문서는 어디에 있습니까? 그것을 잊어 버렸습니다. –

+0

하위 문자열을 다른 문자열로 대체하려는 것 같습니다. SO –

답변

0

당신은 이런 식으로 뭔가를 시도 할 수 있습니다 ..

<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> 

그것은 title 속성을 확인합니다. 존재하는 경우 변수 CPP의 값과 비교합니다. 그러면 matches가 "C++"을 출력합니다.

+0

에 많은 [답변] (http://www.google.com/search?q=site%3Astackoverflow.com+xslt+replace)이 있습니다. @conqenator : 더 긴 제목을 기대합니다 ...하지 마세요. 당신? –

+0

@Alejandro : 죄송합니다. 나는 지금 그것을 바로 잡았다. –

+0

이전에 제공 한 코드로 시도했지만 아무것도 변경되지 않았습니다. 이제 내 코드를 제공하여 내 질문을 편집했습니다. 제목에 Cpp가 있으면 C++로 제목을 가져 오려면 어떻게해야합니까? – Archana