2017-02-08 1 views
1

Моего кода вводаВозможно ли, что извлечение имени изображения из HREF ссылки и последовательности чисел фигурных

<?xml version="1.0" encoding="UTF-8"?> 
<task> 
<info class="- topic/itemgroup task/info "> 
<fig id="status-wf-xsd" class="- topic/fig "> 
<title class="- topic/title ">Status</title> 
<image placement="inline" class="- topic/image " href="ram/raju/alias/code1_Oct31.jpg"></image> 
</fig> 
</info> 
<info class="- topic/itemgroup task/info "> 
<fig id="status-wf-xsd" class="- topic/fig "> 
<title class="- topic/title ">Gnerator</title> 
<image placement="inline" class="- topic/image " href="ragava/raju/alias/code1_Oct32.jpg"></image> 
</fig> 
</info> 
</task> 

XSL я использовал

<?xml version="1.0" encoding="utf-8"?> 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> 
<xsl:template match="node()|@*"> 
<xsl:copy> 
<xsl:apply-templates select="node()|@*"/> 
</xsl:copy> 
</xsl:template> 
<xsl:template match="task"> 
<html> 
<body> 
<xsl:apply-templates/> 
</body> 
</html> 
</xsl:template> 
<xsl:template match="info"> 
<div> 
<span class="figcap"><span class="enumeration fig-enumeration">Figure 1. </span> 
<xsl:value-of select="//fig/title"/> 
</span> 
<div class="figbody"> 
<img xmlns="" src="{substring-after($code, '/alias/')}"/> 
<xsl:value-of select="//image"/> 
</div> 
<xsl:apply-templates/> 
</div>  
</xsl:template> 
<xsl:variable name="code" select="preceding-sibling::fig/image/@href"/> 
<xsl:template match="image"> 
</xsl:template> 
<xsl:template match="fig/title"> 
</xsl:template> 
<xsl:template match="fig"> 
<div class="fignone"> 
<xsl:apply-templates/> 
</div>  
</xsl:template> 
</xsl:stylesheet> 

выхода я получаю, как

<html> 
<body> 
<div> 
<span class="figcap"><span class="enumeration fig-enumeration">Figure 1. </span>Status</span> 
<div class="figbody"><img src=""/></div> 
<div class="fignone"> 
</div> 
</div> 
<div> 
<span class="figcap"><span class="enumeration fig-enumeration">Figure 1. </span>Gnerator</span> 
<div class="figbody"><img src=""/></div> 
<div class="fignone"> 
</div> 
</div> 
</body> 
</html> 

но я хочу, чтобы я выводил последовательность цифр и внутри фигуры внутри фиговой крышки, а затем тег img как xmlns = "" src = "code1_Oct32.jpg"

<html> 
<body> 
<div class="fignone" id="installinfo__status-wf-jar"> 
<div class="figbody"> <img xmlns="" src="img/m1_Oct31.png" /> </div> 
<span class="figcap"><span class="enumeration fig-enumeration">Figure 1. </span>Status</span></div> 
<div> 
<div class="fignone"> 
<div class="figbody"><img src="img/code1_Nov1.jpg"/></div> 
<span class="figcap"><span class="enumeration fig-enumeration">Figure 2. </span>Gnerator</span> 
</div> 
</div> 
</body> 
</html> 

Пожалуйста, помогите мне.

Заранее спасибо

ответ

0

Вы ток переменной code находятся вне любого шаблона, поэтому он не будет относиться к любому info вы сопрягая (я говорю info элемент, потому что ваш текущий код, чтобы создать img тег находится в пределах шаблон, соответствующий info). Тот факт, что вы разместили его до сопоставления с шаблоном image, не имеет значения.

Что вам нужно сделать, это переместить объявление переменной внутри шаблона, соответствующего info, который также устранит необходимость в preceding-sibling

Попробуйте этот XSLT

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> 
    <xsl:template match="task"> 
     <html> 
      <body> 
       <xsl:apply-templates/> 
      </body> 
     </html> 
    </xsl:template> 

    <xsl:template match="info"> 
     <div> 
      <span class="figcap"> 
       <span class="enumeration fig-enumeration">Figure <xsl:number />. </span> 
       <xsl:value-of select="fig/title"/> 
      </span> 
      <div class="figbody"> 
       <xsl:variable name="code" select="fig/image/@href"/> 
       <img xmlns="" src="img/{substring-after($code, '/alias/')}"/> 
      </div> 
      <xsl:apply-templates/> 
     </div>  
    </xsl:template> 

    <xsl:template match="image" /> 

    <xsl:template match="fig/title" /> 

    <xsl:template match="fig"> 
     <div class="fignone"> 
      <xsl:apply-templates/> 
     </div>  
    </xsl:template> 
</xsl:stylesheet> 

Обратите внимание на использование xsl:number тоже, сделайте свою нумерацию.

+0

Спасибо @Tim C, что он работает, и я следую вашим предложениям – User515