Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将img标记添加到xslt生成的输出中_C#_Html_Xml_Image_Xslt - Fatal编程技术网

C# 将img标记添加到xslt生成的输出中

C# 将img标记添加到xslt生成的输出中,c#,html,xml,image,xslt,C#,Html,Xml,Image,Xslt,我正在使用XSLT将XML转换为Html。我必须在生成的html文件中插入一个图像标记。我想从内容的“href”属性中添加其“src”属性的值。但是“src”属性是空的。我将以下内容作为XML的一部分 <body> <sec id="ch1.1"> <title>INTRODUCTION 1</title> <p>The trends of increased functionality,

我正在使用XSLT将XML转换为Html。我必须在生成的html文件中插入一个图像标记。我想从内容的“href”属性中添加其“src”属性的值。但是“src”属性是空的。我将以下内容作为XML的一部分

 <body>
      <sec id="ch1.1">
        <title>INTRODUCTION 1</title>
        <p>The trends of increased functionality, improved performance, reduced size and increased complexity continue to evolve in the automotive electronics market. New system architectures are providing the performance and memory capability necessary to keep up with the hardware performance and software growth required by the automotive market trends. All of this technology growth implies a higher product cost and increased engineering effort required to develop these new products.</p>
        <p>
        <fig id="F22" position="float">
        <label>FIG. 2.7</label>
        <caption><p>Major components of internal combustion engines.</p></caption>
        <graphic content-type="figure" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="R-396_fig0021"/>
        </fig>
        </p>
        <p>In order to meet all of the technical and business objectives, corporations must manage project development cost by increasing the productivity and efficiency of engineering activities, reducing developmental spend rates, shortening product development times, and ensuring that the end objectives for product performance and delivery are met to schedule. Making the economic problem more complex, corporate globalization has moved at an unprecedented rate to capture and expand market share, better serve global customers and improve corporate efficiencies. This global movement has produced a significant amount of economic benefit to the corporate business metrics.</p>

导言1
在汽车电子市场中,功能增加、性能提高、尺寸减小和复杂性增加的趋势继续发展。新的系统架构提供了与汽车市场趋势所需的硬件性能和软件增长保持同步所需的性能和内存能力。所有这些技术增长都意味着开发这些新产品所需的更高的产品成本和更多的工程工作

图2.7 内燃机的主要部件

为了实现所有技术和业务目标,公司必须通过提高工程活动的生产率和效率、降低开发费用、缩短产品开发时间来管理项目开发成本,确保产品性能和交付的最终目标如期实现。企业全球化使经济问题更加复杂,以前所未有的速度占领和扩大市场份额,更好地为全球客户服务,提高企业效率。这一全球运动为公司业务指标带来了巨大的经济效益

我有以下xslt

    <xsl:for-each select="body/sec">
                <p>
                  <h1>
                    <xsl:value-of select="title"/>
                  </h1>
                  <br></br>
                  <xsl:for-each select="p">
                    <xsl:value-of select="text()"/>
                    <xsl:if test="fig">
                     <img alt="{fig/id}" src="{fig/graphic/content/@xlink:href}" style="position:{fig/@position}">


                </img>
    <p><xsl:value-of select="fig/caption/p"/></p>                        
</xsl:if>

                  </xsl:for-each>




我想要以下输出

<p>The trends of increased functionality, improved performance, reduced size and increased complexity continue to evolve in the automotive electronics market. New system architectures are providing the performance and memory capability necessary to keep up with the hardware performance and software growth required by the automotive market trends. All of this technology growth implies a higher product cost and increased engineering effort required to develop these new products.</p><p><img src="../images/R-396_fig0021" style="position:float" alt="Fig 2.7"/>Major components of internal combustion engines.</p><p>In order to meet all of the technical and business objectives, corporations must manage project development cost by increasing the productivity and efficiency of engineering activities, reducing developmental spend rates, shortening product development times, and ensuring that the end objectives for product performance and delivery are met to schedule. Making the economic problem more complex, corporate globalization has moved at an unprecedented rate to capture and expand market share, better serve global customers and improve corporate efficiencies. This global movement has produced a significant amount of economic benefit to the corporate business metrics.</p>
在汽车电子市场上,功能增加、性能提高、尺寸减小和复杂性增加的趋势继续发展。新的系统架构提供了与汽车市场趋势所需的硬件性能和软件增长保持同步所需的性能和内存能力。所有这些技术增长都意味着开发这些新产品所需的更高的产品成本和更多的工程努力。

内燃机的主要部件。

为了实现所有技术和业务目标,公司必须通过提高工程活动的生产率和效率、降低开发费用、缩短产品开发时间以及确保产品性能和交付的最终目标如期实现来管理项目开发成本。企业全球化使经济问题更加复杂,以前所未有的速度占领和扩大市场份额,更好地为全球客户服务,提高企业效率。这一全球运动为公司业务指标带来了巨大的经济效益


看看您是否可以将此样式表调整为适合您的样式表。尽可能避免每次都执行
xsl:for-each
。使用模板匹配,如下所示

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xlink="http://www.w3.org/1999/xlink" exclude-result-prefixes="xlink"
    version="1.0">

    <xsl:output method="html"/>

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

    <xsl:template match="sec|caption/p">
        <xsl:apply-templates/>
    </xsl:template>

    <xsl:template match="sec/title">
        <h1><xsl:apply-templates/></h1>
    </xsl:template>

    <xsl:template match="fig">
        <img src="../images/{graphic/@xlink:href}" style="position:float" alt="{label}"/>
        <xsl:apply-templates select="caption/p"/>
    </xsl:template>

</xsl:stylesheet>