C# 从xslt中的超链接获取href值

C# 从xslt中的超链接获取href值,c#,asp.net,xslt,xml-parsing,C#,Asp.net,Xslt,Xml Parsing,如果我的输入来自xml,如何在xslt中仅获取href值 <a href='http://google.com' target='_blank'>This is the heading </a> 我只需要href值来创建链接。使用以下样式表。这正是我在你先前的问题中所描述的 我需要知道我们将如何调用此模板 匹配a元素的模板由xsl:apply templates语句调用 <?xml version="1.0" encoding="utf-8"?> &l

如果我的输入来自xml,如何在xslt中仅获取
href

<a href='http://google.com' target='_blank'>This is the heading </a>


我只需要
href
值来创建链接。

使用以下样式表。这正是我在你先前的问题中所描述的

我需要知道我们将如何调用此模板

匹配
a
元素的模板由
xsl:apply templates
语句调用

<?xml version="1.0" encoding="utf-8"?>

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   xmlns:fo="http://www.w3.org/1999/XSL/Format">

   <xsl:output method="xml" indent="yes"/>

   <xsl:template match="/">
      <fo:root>

  <fo:layout-master-set>
    <fo:simple-page-master master-name="simple"
                  page-height="29.7cm"
                  page-width="21cm"
                  margin-top="1cm"
                  margin-bottom="2cm"
                  margin-left="2.5cm"
                  margin-right="2.5cm">
      <fo:region-body margin-top="3cm"/>
      <fo:region-before extent="3cm"/>
      <fo:region-after extent="1.5cm"/>
    </fo:simple-page-master>
  </fo:layout-master-set>
  <fo:page-sequence master-reference="simple">

    <fo:flow flow-name="xsl-region-body">

      <fo:block font-size="18pt"
            font-family="sans-serif"
            line-height="24pt"
            space-after.optimum="15pt"
            background-color="blue"
            color="white"
            text-align="center"
            padding-top="3pt">
        <xsl:apply-templates/>
      </fo:block>


      <!-- this defines normal text -->
      <fo:block font-size="12pt"
                font-family="sans-serif"
                line-height="15pt"
                space-after.optimum="3pt"
                text-align="justify">
        The Extensible Markup Language (XML) is a subset of SGML that is completely described in this document. Its goal is to
        enable generic SGML to be served, received, and processed on the Web in the way that is now possible with HTML. XML
        has been designed for ease of implementation and for interoperability with both SGML and HTML.
      </fo:block>

    </fo:flow> <!-- closes the flow element-->
  </fo:page-sequence> <!-- closes the page-sequence -->
</fo:root>
   </xsl:template>

   <xsl:template match="a">
      <fo:basic-link>
           <xsl:attribute name="external-destination">
             <xsl:value-of select="@href"/>
           </xsl:attribute>
           <xsl:value-of select="."/>
      </fo:basic-link>
   </xsl:template>

</xsl:stylesheet>

可扩展标记语言(XML)是本文档中完整描述的SGML的子集。它的目标是
使通用SGML能够在Web上以HTML现在可以采用的方式提供、接收和处理。XML
已设计为易于实现,并与SGML和HTML互操作。
应用于您的输入XML:

<a href='http://google.com' target='_blank'>This is the heading </a>

使用XSLT 2.0、Saxon和Apache FOP 1.0,可以获得正确的输出,即可单击的标题:


你为什么不使用我在这里给出的答案:-而不是再次询问完全相同的问题?我已经尝试过了,但这根本不起作用,如果上面的链接给你href值,你可以尝试使用它。它不识别href,因为它在我的XMl中不是一个单独的字段,并且是Hyperlink中标题标记的一部分。你说什么“它无法识别href”?或“超链接中标题标记的一部分”“?我不熟悉XSL。如果你能给我一个简单的工作版本,从上面的代码生成链接,这将是伟大的。我需要知道我们将如何称呼此模板,提前感谢您的帮助。非常感谢,它是XSL 2.0的一个功能,在1.0中不起作用吗?我在1.0中尝试过,因为我们有这个版本。应该也能用。只需将代码修改为
version=“1.0”
。另外,请考虑接受这两个问题(标记答案左边的记号)。它对我来说仍然无效,有什么办法,所以我可以发给你我的XML和XSL文件,这样你就可以检查吗?不,我不愿意投资更多的解释,这是直截了当的,而且我已经花了很多时间在这上面。记住,人们是免费帮助你的。相反,阅读一本关于XSLT的书或教程(显然,您还没有很好地理解它),您将能够理解我给出的答案。