从XSLT引用XML doctype实体

从XSLT引用XML doctype实体,xml,xslt,Xml,Xslt,我正在尝试访问!XML文件的中的实体元素!使用XSL文件将XML转换为HTML时的DOCTYPE声明。在XML中,我有一个小部件元素,它有一个与对应的属性!实体名称,我希望XSLT将其转换为!实体的值 XML文件 <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE root[ <!ENTITY Widget_Manual "Widget_Manual_File_Name.pdf" > ]> <root

我正在尝试访问
!XML文件的
中的实体
元素!使用XSL文件将XML转换为HTML时的DOCTYPE
声明。在XML中,我有一个
小部件
元素,它有一个与
对应的属性!实体
名称,我希望XSLT将其转换为
!实体的值

XML文件

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

<!DOCTYPE root[
  <!ENTITY Widget_Manual "Widget_Manual_File_Name.pdf" >
]>

<root>
  <!-- I want to convert this to "Widget_Manual_File_Name.pdf" in the transform -->
  <widget entityIdent="Widget_Manual" />
</root>

XSLT文件

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

  <xsl:template match="/">
    <html>
      <head />
      <body>
        <xsl:apply-templates />
      </body>
    </html>
  </xsl:template>

  <xsl:template match="widget">
    <!-- Embed PDF -->
    <object width="800" height="600" type="application/pdf">
      <xsl:attribute name="data">
        <!-- How do I access the !ENTITY's value using the @entityIdent attribute? -->
        <xsl:value-of select="@entityIdent" />
      </xsl:attribute>
    </object>
  </xsl:template>

</xsl:stylesheet>

实际产量

<object width="800" height="600" type="application/pdf" data="Widget_Manual"></object>

期望输出

<object width="800" height="600" type="application/pdf" data="Widget_Manual_File_Name.pdf"></object>

最好只在XML中使用一个实体,这样XML解析器在解析文档时会为您扩展实体

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE root[
  <!ENTITY Widget_Manual "Widget_Manual_File_Name.pdf" >
]>
<root>
    <!-- I want to convert this to "Widget_Manual_File_Name.pdf" in the transform -->
    <widget entityIdent="&Widget_Manual;" />
</root>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
    <xsl:output indent="yes" />
    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="@entityIdent">
        <xsl:attribute name="{name()}">
            <xsl:value-of select="replace(
                                   unparsed-text(base-uri()), 
                                   concat('.*!ENTITY ', ., ' &quot;(.+?)&quot;.*'),
                                   '$1', 
                                   's')"/>
        </xsl:attribute>
    </xsl:template>
</xsl:stylesheet>