Xml 是否可能从href链接和数字序列中提取图像名称

Xml 是否可能从href链接和数字序列中提取图像名称,xml,xslt,Xml,Xslt,我的输入代码 <?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="inlin

我的输入代码

<?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>

图1。
我得到的输出是

<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>

图1。地位
图1。片麻岩
但我希望输出为fig number sequence,并在fig cap内的figtone中,然后将img标记输出为xmlns=”“src=“code1_Oct32.jpg”


图1.现状
图2。片麻岩
请帮助我


提前感谢

您当前变量
code
位于任何模板之外,因此它与您匹配的
info
无关(我说
info
元素,因为您当前创建
img
标记的代码位于匹配
info
的模板内)。您将其放在模板匹配图像之前的事实与此无关

您需要做的是将变量声明移动到模板内匹配
info
,这也将消除
前面的同级

试试这个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
进行编号。

当前变量
code
位于任何模板之外,因此它与匹配的
信息无关(我说的是
info
元素,因为创建
img
标记的当前代码位于模板匹配
info
)中。您将其放在模板匹配
图像之前的事实与此无关

您需要做的是将变量声明移动到模板内匹配
info
,这也将消除
前面的同级

试试这个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
进行编号。

谢谢@Tim C它的工作,我听从你的建议谢谢@Tim C它的工作,我听从你的建议