2017-05-12 12 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

ありがとうございます。私はこれがあなたが意味するものだと願っています。私が質問を投稿したのはこれが初めてです。私はあなたがページのURLが好きかどうか分からない。 – LWD

+0

実際の変換を自分で実行しようとするだけで、あなたのスタイルシートの出力方法が何であるかを知ることさえできません。 –

答えて

1

使用<xsl:output method="html"/>あなたがHTMLパーサが受け入れる出力を生成したい場合。