2012-08-28 64 views
3

我寫了RDF文件,並被要求使用XSL呈現它。用XSL呈現RDF。更新

的RDF代碼(改變)

<?xml version="1.0"?> 
<?xml-stylesheet type="text/xsl" href="XSLTFile1.xslt"?> 
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" 
xmlns:clinic="http://www.computing-services.co.il" 
xml:base="http://www.computing-services.co.il"> 
<rdfs:Class rdf:ID="Patient"> 
<rdfs:comment> 
the class of patient 
</rdfs:comment> 
</rdfs:Class> 
<rdf:Property rdf:ID="ID"> 
<rdfs:comment> 
Patient's ID 
</rdfs:comment> 
<rdfs:domain rdf:resource="#Patient"/> 
<rdfs:range rdf:resource="http://www.w3.org/2000/01/rdf-schema#Literal"/> 
</rdf:Property> 
<rdf:Property rdf:ID="Name"> 
<rdfs:comment> 
Patient's Name 
</rdfs:comment> 
<rdfs:domain rdf:resource="#Patient"/> 
<rdfs:range rdf:resource="http://www.w3.org/2000/01/rdf-schema#Literal"/> 
</rdf:Property> 
    <rdf:Property rdf:ID="Age"> 
    <rdfs:comment> 
     Patient's Age 
    </rdfs:comment> 
    <rdfs:domain rdf:resource="#Patient"/> 
    <rdfs:range rdf:resource="http://www.w3.org/2000/01/rdf-schema#Literal"/> 
    </rdf:Property> 
    <rdf:Property rdf:ID="Sex"> 
    <rdfs:comment> 
     Patient's Sex 
    </rdfs:comment> 
    <rdfs:domain rdf:resource="#Patient"/> 
    <rdfs:range rdf:resource="http://www.w3.org/2000/01/rdf-schema#Literal"/> 
    </rdf:Property> 
<rdfs:Class rdf:ID="Disease"> 
<rdfs:comment> 
the class of diseases 
</rdfs:comment> 
</rdfs:Class> 
    <rdfs:Class rdf:ID="CancDiseases"> 
    <rdfs:comment> 
     the class of cancerous diseases 
    </rdfs:comment> 
    <rdfs:subClassOf rdf:resource="#Disease"/> 
    </rdfs:Class> 
    <rdfs:Class rdf:ID="CntDiseases"> 
    <rdfs:comment> 
     the class of contagious diseases 
    </rdfs:comment> 
    <rdfs:subClassOf rdf:resource="#Disease"/> 
    </rdfs:Class> 
    <rdfs:Class rdf:ID="Traumas"> 
    <rdfs:comment> 
     the class of traumas 
    </rdfs:comment> 
    <rdfs:subClassOf rdf:resource="#Disease"/> 
    </rdfs:Class> 
    <rdfs:Class rdf:ID="IntDiseases"> 
    <rdfs:comment> 
     the class of Internal diseases 
    </rdfs:comment> 
    <rdfs:subClassOf rdf:resource="#Disease"/> 
    </rdfs:Class> 
    <rdfs:Class rdf:ID="EmIntDiseases"> 
    <rdfs:comment> 
     the class of Emerging diseases 
    </rdfs:comment> 
    <rdfs:subClassOf rdf:resource="#IntDiseases"/> 
    </rdfs:Class> 
    <rdfs:Class rdf:ID="ChIntDiseases"> 
    <rdfs:comment> 
     the class of Chronic diseases 
    </rdfs:comment> 
    <rdfs:subClassOf rdf:resource="#IntDiseases"/> 
    </rdfs:Class> 
    <rdfs:Class rdf:ID="Treatment"> 
    <rdfs:comment> 
     the class of treatment 
    </rdfs:comment> 
    </rdfs:Class> 
    <rdfs:Class rdf:ID="Medication"> 
    <rdfs:comment> 
     the class of medications 
    </rdfs:comment> 
    <rdfs:subClassOf rdf:resource="#Treatment"/> 
    </rdfs:Class> 
    <rdfs:Class rdf:ID="Procedure"> 
    <rdfs:comment> 
     the class of procedures 
    </rdfs:comment> 
    <rdfs:subClassOf rdf:resource="#Treatment"/> 
    </rdfs:Class> 


<rdf:Property rdf:ID="isSick"> 
<rdfs:domain rdf:resource="#Patient"/> 
<rdfs:range rdf:resource="#Disease"/> 
</rdf:Property> 
    <rdf:Property rdf:ID="gets"> 
    <rdfs:domain rdf:resource="#Patient"/> 
    <rdfs:range rdf:resource="#Treatment"/> 
    </rdf:Property> 
    <rdf:Property rdf:ID="helpsFrom"> 
    <rdfs:domain rdf:resource="#Treatment"/> 
    <rdfs:range rdf:resource="#Disease"/> 
    </rdf:Property> 







      <clinic:ChIntDiseases rdf:ID="chrone"/> 
      <clinic:ChIntDiseases rdf:ID="diabetes"/> 
      <clinic:Traumas rdf:ID="BrokenLeg"/> 
      <clinic:EmIntDiseases rdf:ID="Appendicite"/> 
      <clinic:CancDiseases rdf:ID="BreastCancer"/> 
      <clinic:CancDiseases rdf:ID="LungCancer"/> 






    <clinic:Medication rdf:ID="Insuline"> 
    <clinic:helpsFrom rdf:resource="#diabetes"/> 
    </clinic:Medication> 
    <clinic:Medication rdf:ID="Pentassa"> 
    <clinic:helpsFrom rdf:resource="#chrone"/> 
    </clinic:Medication> 
    <clinic:Medication rdf:ID="Raffasal"> 
    <clinic:helpsFrom rdf:resource="#chrone"/> 
    </clinic:Medication> 
    <clinic:Medication rdf:ID="Advil"> 
    <clinic:helpsFrom rdf:resource="#BrokenLeg"/> 
    <clinic:helpsFrom rdf:resource="#Appendicite"/> 
    </clinic:Medication> 
    <clinic:Procedure rdf:ID="Sigmoscopia"> 
    <clinic:helpsFrom rdf:resource="#chrone"/> 
    </clinic:Procedure> 
    <clinic:Procedure rdf:ID="Chemo"> 
    <clinic:helpsFrom rdf:resource="#BreastCancer"/> 
    <clinic:helpsFrom rdf:resource="#LungCancer"/> 
    </clinic:Procedure> 



      <clinic:Patient rdf:ID="p23456"> 
      <clinic:Name>Linda Jones</clinic:Name> 
      <clinic:Sex>Female</clinic:Sex> 
      <clinic:Age>56</clinic:Age> 
      <clinic:isSic> 
       <rdf:Bag> 
       <rdf:li rdf:resource="#chrone"/> 
       <rdf:li rdf:resource="#diabetes"/> 
       </rdf:Bag> 
      </clinic:isSic> 
      <clinic:gets> 
       <rdf:Bag> 
       <rdf:li rdf:resource="#Pentassa"/> 
       <rdf:li rdf:resource="#Insuline"/> 
       </rdf:Bag> 
      </clinic:gets> 
      </clinic:Patient> 
    <clinic:Patient rdf:ID="p12345"> 
    <clinic:Name>Moshe Koen</clinic:Name> 
    <clinic:Sex>Male</clinic:Sex> 
    <clinic:Age>70</clinic:Age> 
    <clinic:isSic> 
     <rdf:Bag> 
     <rdf:li rdf:resource="#diabetes"/> 
     </rdf:Bag> 
    </clinic:isSic> 
    <clinic:gets> 
     <rdf:Bag> 
     <rdf:li rdf:resource="#Insuline"/> 
     </rdf:Bag> 
    </clinic:gets> 
    </clinic:Patient> 
    <clinic:Patient rdf:ID="p34567"> 
    <clinic:Name>Ofer Meleh</clinic:Name> 
    <clinic:Sex>Male</clinic:Sex> 
    <clinic:Age>25</clinic:Age> 
    <clinic:isSic> 
     <rdf:Bag> 
     <rdf:li rdf:resource="#BrokenLeg"/> 
     </rdf:Bag> 
    </clinic:isSic> 
    <clinic:gets> 
     <rdf:Bag> 
     <rdf:li rdf:resource="#Advil"/> 
     </rdf:Bag> 
    </clinic:gets> 
    </clinic:Patient> 
    <clinic:Patient rdf:ID="p45678"> 
    <clinic:Name>Itzhak Rabinovich</clinic:Name> 
    <clinic:Sex>Male</clinic:Sex> 
    <clinic:Age>38</clinic:Age> 
    <clinic:isSic> 
     <rdf:Bag> 
     <rdf:li rdf:resource="#LungCancer"/> 
     </rdf:Bag> 
    </clinic:isSic> 
    <clinic:gets> 
     <rdf:Bag> 
     <rdf:li rdf:resource="#Chemo"/> 
     </rdf:Bag> 
    </clinic:gets> 
    </clinic:Patient> 
    <clinic:Patient rdf:ID="p56789"> 
    <clinic:Name>Golda Zilber</clinic:Name> 
    <clinic:Sex>Female</clinic:Sex> 
    <clinic:Age>45</clinic:Age> 
    <clinic:isSic> 
     <rdf:Bag> 
     <rdf:li rdf:resource="#BreastCancer"/> 
     <rdf:li rdf:resource="#Appendicite"/> 
     </rdf:Bag> 
    </clinic:isSic> 
    <clinic:gets> 
     <rdf:Bag> 
     <rdf:li rdf:resource="#Chemo"/> 
     <rdf:li rdf:resource="#Advil"/> 
     </rdf:Bag> 
    </clinic:gets> 
    </clinic:Patient> 




</rdf:RDF> 

`

有病人,他們的疾病和治療(我改變了以前的RDFS部分) 我需要的患者有序列表(與他們的個人數據)和每個病人 - 他的疾病和治療表。

它應該是這樣的:

這是我的新嘗試寫XSL

 <?xml version="1.0"?> 
<xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" 
    xmlns:clinic="http://www.infomed.co.il"> 
    <xsl:output method="html" indent="yes"/> 

    <xsl:template match="/rdf:RDF/clinic:Patient"> 
    <html> 
     <body> 
     <ol> 
      <xsl:apply-templates select="/rdf:RDF/clinic:Patient" /> 
     </ol> 
     </body> 
    </html> 
    </xsl:template> 

    <xsl:template match="clinic:Patient"> 
    <li> 
     Name <xsl:value-of select="clinic:Name"/> 
     Age <xsl:value-of select="clinic:Age"/> 
     Sex <xsl:value-of select="clinic:Sex"/> 
     <table> 
     <tr> 
      <th>Disease</th> 
      <xsl:apply-templates select="clinic:isSic" /> 
      <th>Treatment</th> 
      <xsl:apply-templates select="clinic:gets" /> 
     </tr> 


     </table> 
    </li> 
    </xsl:template> 

    <xsl:template match="clinic:isSic"> 
    <xsl:variable name="resource" select="@rdf:resource"/> 
     <td> 
     <xsl:value-of select="translate(@rdf:resource,'#','')"/> 
     </td> 
    </xsl:template> 
    <xsl:template match="clinic:gets"> 
    <xsl:variable name="resource" select="@rdf:resource"/> 
    <td> 
     <xsl:value-of select="translate(@rdf:resource,'#','')"/> 
    </td> 
    </xsl:template> 


</xsl:stylesheet> 

它仍然無法正常工作,但至少我現在看到的患者數據。它看起來像這樣:

患者的類別患者的ID患者的姓名患者的年齡患者的性別疾病類別癌症疾病類別傳染病類別創傷類別內部疾病類別新發疾病慢性病類治療類藥物治療類程序類Linda Jones女56 Moshe Koen男70 Ofer Meleh男25 Itzhak Rabinovich男38 Golda Zilber女45

我會感謝任何幫助,使它像這個:

+0

請編輯問題並提供轉換的確切結果 - 讀者不應該猜測,這會阻止很多人回答。 –

+0

謝謝指教!我編輯了帖子 –

+0

@Michael Shaf,如果這是一個單獨的,或者你完全手動控制RDF/XML文件結構,那麼這樣做很好。但請記住,RDF/XML可以通過多種方式序列化相同的RDF數據。換句話說:具有非常不同的XML結構的兩個文檔可能會顯示相同的信息。如果您將文件放入三重商店,然後將其導出,則看起來會有所不同。這就是爲什麼編寫XSLT幾乎是不可能的,它強大的適用於所有合法的RDF輸入。 –

回答

2

更新的答案,以反映問題的變化:

你更新的樣式表仍然有幾個問題:

  • 爲的命名空間與您的XSLT不正確的命名空間URI聲明中。它需要映射到http://www.computing-services.co.il以使您的XPath語句匹配。
  • 我更改了在/rdf:RDF/clinic:Patient上匹配的模板以匹配根節點/,以確保控制樣式表處理方式。否則,默認模板將在元素和文本節點(發送文本和空白)上匹配,直到它碰到clinic:Patent元素並執行模板。
  • 如果你想爲疾病和治療分開行,那麼你需要關閉tr並在<tr>Treatment</tr>之前開始一個新行。
  • 在爲clinic:isSicclinic:gets模板,你不需要資源變量,路徑@rdf:資源is RDF:袋/ RDF:李/ @ RDF:resource`。

我做了那些調整到你的樣式表:

<?xml version="1.0"?> 
<xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" 
    xmlns:clinic="http://www.computing-services.co.il"> 
    <xsl:output method="html" indent="yes"/> 

    <xsl:template match="/"> 
    <html> 
     <body> 
     <ol> 
      <xsl:apply-templates select="/rdf:RDF/clinic:Patient" /> 
     </ol> 
     </body> 
    </html> 
    </xsl:template> 

    <xsl:template match="clinic:Patient"> 
    <li> 
     Name <xsl:value-of select="clinic:Name"/> 
     Age <xsl:value-of select="clinic:Age"/> 
     Sex <xsl:value-of select="clinic:Sex"/> 
     <table border="1"> 
     <tr> 
      <th>Disease</th> 
      <xsl:apply-templates select="clinic:isSic" /> 
     </tr> 
     <tr> 
      <th>Treatment</th> 
      <xsl:apply-templates select="clinic:gets" /> 
     </tr> 
     </table> 
    </li> 
    </xsl:template> 

    <xsl:template match="clinic:isSic"> 
     <xsl:apply-templates select="rdf:Bag/rdf:li/@rdf:resource"/> 
    </xsl:template> 

    <xsl:template match="clinic:gets"> 
     <xsl:apply-templates select="rdf:Bag/rdf:li/@rdf:resource"/> 
    </xsl:template> 

    <xsl:template match="rdf:Bag/rdf:li/@rdf:resource"> 
    <td> 
     <xsl:value-of select="translate(.,'#','')"/> 
    </td> 
    </xsl:template> 
</xsl:stylesheet> 

作爲asside,目前的邏輯似乎假定存在疾病和治療的1對1的映射。如果有多種治療方法,您將如何區分或瞭解哪些疾病與哪種疾病相對應?

+0

Mads,謝謝!我知道我在命名空間中做了一些錯誤。 但它仍然無法正常工作,儘管我根據您的建議進行了更改。我只得到沒有任何內容的白頁:-( –

+0

嗨,Mads.Can你看到更新,請嗎? –

+0

@Michael Shaf - 我根據XML和你的XSLT的變化更新了我的答案。 –

1

如果您試圖將RDF顯示爲HTML,我認爲您應該使用RDFa。您可以很容易地使用RDFa標記生成HTML,並且任何人通過RDFa知道的插件查看頁面或代理可以獲取和使用RDF,都會帶來額外的好處。如果你只是使用XSL把它變成HTML,你就會「失去」RDF。

0

RDF 肯定不是使用XML技術進行解析!