Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.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# 在XSLT中解析处理指令_C#_Xml_Xslt_Processing Instruction - Fatal编程技术网

C# 在XSLT中解析处理指令

C# 在XSLT中解析处理指令,c#,xml,xslt,processing-instruction,C#,Xml,Xslt,Processing Instruction,我有以下XML <sec xmlns:xlink="http://www.w3.org/1999/xlink" id="fm2" sec-type="other"> <title /> <?SAE page="ii"?> <p><bold>Other SAE books of interest:</bold></p> <p><bold>Electric and Hybrid

我有以下XML

<sec xmlns:xlink="http://www.w3.org/1999/xlink" id="fm2" sec-type="other">
  <title />
  <?SAE page="ii"?>
  <p><bold>Other SAE books of interest:</bold></p>
  <p><bold>Electric and Hybrid-Electric Vehicles</bold></p>
  <p>Edited by Ronald K. Jurgen</p>
  <p>(Product Code: PT-143.SET)</p>
  <p><bold>Diesel Emissions and Their Control</bold></p>
  <p>By Magdi K. Khair and W. Addy Majewski</p>
  <p>(Product Code: R-303)</p>
  <p><bold>Hybrid Powered Vehicles, Second Edition</bold></p>
  <p>By John M. German</p>
  <p>(Product Code: T-125)</p>
  <p>For more information or to order a book, contact SAE International at</p>
  <p>400 Commonwealth Drive, Warrendale, PA 15096-0001, USA;</p>
  <p>phone 877-606-7323 (U.S. and Canada only) or 724-776-4970 (outside U.S. and Canada);</p>
  <p>fax 724-776-0790;</p>
  <p>email <email>CustomerService@sae.org</email>;</p>
  <p>website <uri xlink:href="http://books.sae.org">http://books.sae.org</uri>.</p>
</sec>
但是我想要

**Energy Consumption of Commercial Vehicles**
Commercial vehicle manufacturing and operation is a major source of energy consumption globally. In 2009, the United States consumed 23&#x0025; of the global petroleum production &#x005B;1.3 &#x005D;. According to the U.S. Department of Energy, 72&#x0025;Page 8 of the U.S. petroleum consumption is for transportation. Commercial vehicles consumed up to 18.7&#x0025; of the total energy consumption in transportation in the United States. In other words, commercial vehicles in the United States alone consumed over 3&#x0025; of the global petroleum production in 2009 &#x005B;

现在解释如何获得此输出??我希望您现在能更容易理解我的问题。

如果您想简单地复制整个内容,只需执行以下操作:

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

这称为标识模板。然后,创建模板匹配以覆盖复制的节点。如果是外部参照,可以尝试

<xsl:template match="xref">
    <a href="{@rid}">
        <xsl:apply-templates/>
    </a>
</xsl:template>

您可以使用

<xsl:template match="processing-instruction('SAE')">
  <xsl:value-of select="." />
</xsl:template>

这只是一条处理指令,可能是您的根节点中缺少名称空间声明。Lamsen我已经在我的根标记中添加了这个名称空间。但它仍然不起作用。。我的根标签是我试着在这里运行你的代码,看起来还可以。你能编辑你的帖子来添加更多关于样式表的信息吗?当我试图运行这段代码时,在我的例子中,带有粗体值的p标记现在没有解析。。只解析简单的p标记。但是我想解析这个p标签,并在输出中加粗内容。怎么做?在我的例子中,外部参照标记也没有解析。每当外部参照标记出现时,它只会停在那里并找到另一个p标记。如何同时解析外部参照标记?是否要复制整个XML?或者只是其中的一部分?谢谢。这是一个很大的帮助。你能告诉我如何解析外部参照标签吗?因为在我的例子中,无论在哪里找到外部参照标记,它都不会写入在外部参照标记之后写入的内容。我希望我的问题对您来说是可以理解的,或者我应该更详细地解释一下吗?您可能想先尝试搜索一下。其他人在你之前也会遇到同样的问题,我相信你会找到一个例子来解释它。
<xsl:template match="node()|@*">
    <xsl:copy>
        <xsl:apply-templates select="node()|@*"/>
    </xsl:copy>
</xsl:template>
<xsl:template match="xref">
    <a href="{@rid}">
        <xsl:apply-templates/>
    </a>
</xsl:template>
<xsl:template match="processing-instruction('SAE')">
  <xsl:value-of select="." />
</xsl:template>
<xsl:template match="processing-instruction('SAE')">
  <xsl:variable name="start-token">page="</xsl:variable>
  <xsl:variable name="end-token">"</xsl:variable>
  <xsl:variable name="temp" select="substring-after(., $start-token)" />

  <xsl:value-of select="substring-before($temp, $end-token)" />
  <!-- output: "ii" -->
</xsl:template>