2014-01-23 54 views
0

我是xslt的新手。我有以下xml和xslt,我需要使用XslCompiledTranform轉換爲html。 我有以下XML使用xslt傳遞xml標籤的屬性值

<ref-list id="RL10"> 
<label> 
    <bold>7.0</bold> 
</label> 
<title> 
    <bold>References</bold> 
</title> 
    <ref id="R66" content-type="references"> 
    <label>2</label> 
    <mixed-citation publication-type="book"> 
    <person-group person-group-type="author"> 
     <name> 
     <surname>Chown,</surname> 
     <given-names>Bill</given-names> 
     </name> 
    </person-group>, and 
    <person-group person-group-type="author"> 
     <name> 
     <surname>Lange</surname> 
     <given-names>Michelle</given-names> 
     </name> 
    </person-group>. &#x201C; 
    <source>Modernizing System Development: Requirements&#x002d;Based, Model&#x002d;Driven Design, Implementation and Test</source>.&#x201D; 
    <publisher-name>Mentor Graphics Corp., ERTS</publisher-name>, 
    <month>Feb.</month> 
    <year>2012</year>. 
    </mixed-citation></ref> 
    <ref id="R67" content-type="references"> 
    <label>3</label> 
     <mixed-citation publication-type="journal"> 
     <person-group person-group-type="author"> 
     <name> 
     <surname>Blyler,</surname> 
     <given-names>John</given-names> 
     </name> 
     </person-group>. &#x201C; 
     <article-title>Model&#x002d;Driven Development Is Key to Low Power</article-title>.&#x201D; 
     <source>Chip Design Magazine &#x002d; JB&#x2019;s Circuit</source>, 
     <month>Dec.</month> 
     <day>6</day>, 
     <year>2012</year>. 
     <uri xlink:href="http://www.chipdesignmag.com/blyler/2012/12/06/model-driven-development-key-to-low-power/">http:&#x002F;&#x002F;www.chipdesignmag.com&#x002F;blyler&#x002F;2012&#x002F;12&#x002F;06&#x002F;model&#x002d;driven&#x002d;development&#x002d;key&#x002d;to&#x002d;low&#x002d;power&#x002F;</uri>. 
     </mixed-citation> 
    </ref> 
</ref-list> 

我有以下XSLT

<xsl:template match="ref-list/ref"> 
    <html> 
    <head></head> 
    <body> 
    <xsl:apply-templates/> 
    </body> 
    </html> 
</xsl:template> 

<xsl:template match="ref-list/ref"> 
    <p> 
    <xsl:value-of select="label"/> 
    <xsl:for-each select="mixed-citation"> 
      <xsl:for-each select="person-group/name"> 
      <xsl:value-of select="given-names"/> 
      <xsl:value-of select="surnames"/> 
      </xsl:for-each> 
     <xsl:text>,</xsl:text> 
     <xsl:value-of select="source"/> 
     <xsl:text>,</xsl:text> 
     <xsl:value-of select="publisher-name"/> 
     <xsl:text>,</xsl:text> 
     <xsl:value-of select="day"/> 
     <xsl:text>,</xsl:text> 
     <xsl:value-of select="month"/> 
     <xsl:text>,</xsl:text> 
     <xsl:value-of select="year"/> 
     <xsl:text>,</xsl:text> 
     <xsl:for-each select="uri"> 
     <xsl:value-of select="."/> 
     </xsl:for-each> 
     <xsl:text>,</xsl:text> 
     <xsl:value-of select="article-title"/> 
     <xsl:text>,</xsl:text> 
     <xsl:value-of select="publisher-loc"/> 
     <xsl:text>,</xsl:text> 
     <xsl:value-of select="volume"/> 
     <xsl:text>,</xsl:text> 
     <xsl:value-of select="issue"/> 
    </xsl:for-each> 
    </p> 
</xsl:template> 

我不得不改變我的XML使用XSLT HTML。但在轉變的同時,它說「xlink」是一個未聲明的前綴。我不知道如何解析它。 我需要輸出解析uri標籤有xlink作爲其屬性。我不知道如何解析任何xml標籤的任何屬性。任何人都可以請解釋如何解析任何具有其屬性的XML標籤?

+0

請參閱以下資源: http://stackoverflow.com/questions/8352947/passing-xml-attribute-value-to-html-atrribute-value-using-xslt 的http:// stackoverflow.com/questions/13090401/using-xsl-to-pass-an-xml-attribute-as-an-id-into-html http://stackoverflow.com/questions/6050044/how-do -i-pass-a-xml-attribute-to-xslt-parameter –

+0

我不知道我要錯哪裏,但仍然收到相同的錯誤。錯誤表示xlink未在Xml中聲明。有一種方法可以排除前綴,但我不知道如何去做。可能是這可以解決我的問題。是否有任何方法在xslt我可以排除前綴,即xlink? – user

+1

它被稱爲命名空間。你的xml的根標籤應該包含'xmlns:xlink =「http://www.w3.org/1999/xlink」'。如果沒有,每次在標籤中加入'xlink:href'都應該包含它。 –

回答

1

它被稱爲命名空間。你的XML的根標籤應包含

xmlns:xlink="http://www.w3.org/1999/xlink 

如果沒有它應該包括每次你在你的標籤添加xlink:href

+0

,但在此命名空間後<?xml version =「1.0」encoding =「utf-8」xmlns:xlink =「http://www.w3.org/1999/xlink」?>我收到此錯誤「The」 :「字符,十六進制值0 * 3A,不能包含在名稱中,第1行,第43位。 – user

+0

不是xml聲明,後面的標記是根標記。 –

+0

好的確定..謝謝..它工作正常。 – user