C# 使用XML和XSLT显示图像

C# 使用XML和XSLT显示图像,c#,xml,xslt,C#,Xml,Xslt,我的XML如下所示: <?xml version="1.0" encoding="ISO-8859-1"?> <chapter id="ch01"> <sect1> <title>Wattage</title> <para>Paragraph1</para> <para>Paragraph2</para> &l

我的XML如下所示:

<?xml version="1.0" encoding="ISO-8859-1"?>    
<chapter id="ch01">
    <sect1>
        <title>Wattage</title>
        <para>Paragraph1</para>
        <para>Paragraph2</para>
        <para><figure>
                <caption>
                    <para>
                    <i>Sample image caption</i></para>
                </caption>
                <img src="myimagepath\cover_front.jpg"/>
            </figure>
        </para>
    </sect1>
</chapter>
我在HTML页面上显示图像时遇到问题,我正在使用XSLT通过C aspx页面呈现XML

我的XSLT如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
        <html> 
            <body>
                <h2>My Book</h2>
                <xsl:apply-templates select="chapter/sect1" />
            </body>
        </html>
    </xsl:template>
    <xsl:template match="chapter/sect1">
        <xsl:apply-templates select="title" />
        <xsl:apply-templates select="para/figure" />
        <br />
    </xsl:template>
    <xsl:template match="title">
        <b><span style="font-size=22px;">
                <xsl:value-of select="." />
            </span>
        </b>
        <br />
    </xsl:template>
    <xsl:template match="para/figure">
        <xsl:element name="img">
            <xsl:attribute name="src">
                <xsl:value-of select="." />
            </xsl:attribute>
        </xsl:element>
    </xsl:template>
</xsl:stylesheet>

我的图像未使用上述XSLT显示。谁能帮忙吗。我是XSLT新手

渲染para/figure的点与您的想法不完全一致,即您选择的点。对于图像源,实际上应渲染以下所有内容:

<caption><para><i>Sample image caption</i></para></caption>
<img src="myimagepath\cover_front.jpg"/>
尝试将此模板更改为:

<xsl:template match="para/figure">
    <img src="{img/@src}" />
</xsl:template>
这是从记忆开始的,所以:

para/figure有两个子元素caption和img 因此,我们希望输出一个标记img,名称与属性src相同,并且我们希望src是当前节点img元素的src属性@==属性。花括号使magic能够将值放入正在渲染的标记的内联中。
您是在服务器端还是客户端进行转换?图像路径是相对于客户端看到的URL还是XSLT文件的?您确定您的XML结构良好吗?您是否有意这样做:第1段?正如@Rob所建议的,我通过添加两个结束标记来完成输入XML。检查你的答案时要注意这一点。非常感谢你,默夫。现在正在我的aspx页面中显示图像。对于罗兰问题,我正在通过XML.Net控件进行服务器端XSLT转换。我的图像路径是相对于URL的。我的问题是,当我的图像路径相对于XSLT文件时,代码是什么?你能解释一下这个概念吗。非常感谢。我的XML中有多个para标记用于单个父标记。