2017-05-12 18 views
0

我的網站內容爲xml文件,並使用xsl樣式表顯示,因此客戶可以輕鬆編輯內容,但如果使用amp-img標籤,則xsl轉換會自動關閉標籤甚至儘管我在樣式表中使用了結束標籤。然後,當我使用w3c html驗證器來測試頁面時,它會發出錯誤,指出以下標記未關閉。以下是錯誤的示例:使用xslt與<amp-img>

在非空的HTML元素上使用的自閉合語法(/>)。忽略斜線並將其視​​爲開始標記。

錯誤:看到了結束標記div,但有開放元素。

<amp-img width="30" height="30" src="/images/camera.svg" /> 

有誰能告訴我該如何處理這個問題?

這裏是樣式表的一部分:

<xsl:template match="/"> 
<xsl:apply-templates select="//localItem" /> 
</xsl:template> 

<xsl:template match="localItem"> 
<div itemscope="itemscope" itemtype="http://schema.org/BreadcrumbList"> 
<div class="breadCrumb" itemprop="itemListElement" itemscope="itemscope" itemtype="http://schema.org/ListItem"> 
    <a itemprop="item" href="localSights.aspx"> 
    <h2 class="traffic" itemprop="name"> 
     <xsl:value-of select="heading" /> 
    </h2> 
    <meta itemprop="position"> 
     <xsl:attribute name="content"> 
     <xsl:value-of select="@position"/> 
     </xsl:attribute> 
    </meta> 
    <div class="breadCrumbIcon"> 
     <amp-img> 
    <xsl:attribute name="width"> 
     <xsl:value-of select="image/@width"/> 
    </xsl:attribute> 
     <xsl:attribute name="height"> 
     <xsl:value-of select="image/@height"/> 
    </xsl:attribute> 
     <xsl:attribute name="src"> 
     <xsl:value-of select="image"/> 
    </xsl:attribute> 
    </amp-img> 
    </div> 
    <div class="description"> 
      <xsl:value-of select="paragraph"/> 
    </div> 
    </a> 
</div> 
</div> 
</xsl:template> 

這裏是從XML文件中的元素:

<page name="nearby"> 
    <localItem position="1"> 
     <heading>Local Sights</heading> 
     <paragraph> 
     Lincoln is a historic city...Click here to see some of the many sights 
     </paragraph> 
     <image alt="drawing of camera" width="30" height="30">/images/camera.svg</image> 
    </localItem> 
</page> 

這裏是在放大器的頁代碼vb.net:

 <% 
     Dim root As XmlElement 
     root = Cache("content").documentElement 
     Dim styleFile As String = (EdenHouseContent.webRoot & "\nearby\default.xslt") 
     Response.Write(httpFunctions.transformXML(root.OuterXml, styleFile)) 
    %> 

這裏是上面稱爲的使用定義函數:

Public Shared Function transformXML(xmlNode As Object, styleSheet As Object) As String 
    Dim reader As System.Xml.XmlReader = System.Xml.XmlReader.Create(New IO.StringReader(xmlNode.ToString())) 
    reader.MoveToContent() 

    'Load the style sheet. 
    Dim xslt As System.Xml.Xsl.XslCompiledTransform = New System.Xml.Xsl.XslCompiledTransform() 
    'xslt.OutputSettings.ConformanceLevel = System.Xml.ConformanceLevel.Fragment 
    xslt.Load(styleSheet) 

    ' Transform the node fragment 
    Dim settings As System.Xml.XmlWriterSettings = New System.Xml.XmlWriterSettings 
    settings.OmitXmlDeclaration = True 
    settings.Indent = True 
    settings.ConformanceLevel = System.Xml.ConformanceLevel.Auto 
    settings.CloseOutput = False 

    Dim sw As New System.IO.StringWriter() 
    Dim writer As Object = System.Xml.XmlWriter.Create(sw, settings) 
    xslt.Transform(reader, writer) 
    Return (sw.ToString()) 

End Function 

這裏是樣式表的頂部:

<?xml version="1.0" ?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"> 
+0

請發表[mcve]。 –

+0

謝謝你看這個。我希望這是你的意思。這是我第一次發佈一個問題。我不確定您是否想要網頁的網址。 – LWD

+0

我什至不能告訴你的樣式表的輸出方法是什麼,更不用說嘗試自己運行實際的轉換。 –

回答

1

使用<xsl:output method="html"/>如果要產生輸出HTML解析器會接受。