2016-06-01 1 views
0

У меня есть и XHtml документ в этом формате. Как использовать XSL для перемещения всех тегов img внутри div.Xsl transform, remove/move tag tag

<html xmlns="http://www.w3.org/1999/xhtml"> 
 

 
<head> 
 
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> 
 
    <title>Title</title> 
 
    <link href="css/style.css" rel="stylesheet" type="text/css" /> 
 
</head> 
 

 
<body> 
 
    <div class="article"> 
 
    <div class="docTitles"> 
 
     <h1 class="title">doc title</h1> 
 
    </div> 
 
    <div class="section"> 
 
     <h2 class="generic">subtitle</h2> 
 
     <p> 
 
     <img alt="Image" src="images/{D11F8168-E415-498A-BC1C-6FEF3514B120}.JPG" width="200" />paragraph</p> 
 
    </div> 
 
    </div> 
 
    <div id="images"></div> 
 
</body> 
 

 
</html>

Вот результат я ищу, все теги изображений перемещается внутри изображения DIV

<html xmlns="http://www.w3.org/1999/xhtml"> 
 

 
<head> 
 
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> 
 
    <title>Title</title> 
 
    <link href="css/style.css" rel="stylesheet" type="text/css" /> 
 
</head> 
 

 
<body> 
 
    <div class="article"> 
 
    <div class="docTitles"> 
 
     <h1 class="title">doc title</h1> 
 
    </div> 
 
    <div class="section"> 
 
     <h2 class="generic">subtitle</h2> 
 
     <p>paragraph</p> 
 
    </div> 
 
    </div> 
 
    <div id="images"> 
 
    <img alt="Image" src="images/{D11F8168-E415-498A-BC1C-6FEF3514B120}.JPG" width="200" /> 
 
    </div> 
 
</body> 
 

 
</html>

+1

Как выглядит ваш желаемый результат? Измените свой вопрос соответствующим образом. – zx485

ответ

1

Try:

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:x="http://www.w3.org/1999/xhtml"> 
<xsl:output method="xml" omit-xml-declaration="yes" version="1.0" encoding="utf-8" indent="yes"/> 
<xsl:strip-space elements="*"/> 

<!-- identity transform --> 
<xsl:template match="@*|node()"> 
    <xsl:copy> 
     <xsl:apply-templates select="@*|node()"/> 
    </xsl:copy> 
</xsl:template> 

<xsl:template match="x:img"/> 

<xsl:template match="x:div[@id='images']"> 
    <xsl:copy> 
     <xsl:copy-of select="//x:img"/> 
    </xsl:copy> 
</xsl:template> 

</xsl:stylesheet> 
+0

работает как шарм. благодаря! – user3799826

 Смежные вопросы

  • Нет связанных вопросов^_^