0

我有这样的xml:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<?xml-stylesheet type="text/xsl" href="index.xsl"?>
<content>
    <include xmlns="http://www.w3.org/2001/XInclude" href="static.xml" parse="xml"/>
    <user authorizeds="false"/>
</content>

但是 webstorm XSLTRunner 实际上并没有执行包含。如何启用它?我在 Windows 8 上运行它,最新的 java 版本。

4

1 回答 1

1

使用 XInclude 的 XSLT 实现:

<content xmlns:xi="http://www.w3.org/2001/XInclude">
  <xi:include href="example.xml"/>
  <user authorizeds="false"/>
</content>

通过将模板添加到现有样式表:

<!-- ==============================================================
     XInclude implementation

     Implements XInclude by processing the entire doc
     to produce a single result tree with all the includes resolved
     and then applies the normal template processing to that document.
     ==============================================================-->
<xsl:template match="/">
 <xsl:choose>
   <xsl:when test="//xi:include">
     <xsl:variable name="resolved-doc">
       <xsl:apply-templates  mode="xinclude"/>
     </xsl:variable>
     <xsl:apply-templates select="$resolved-doc" mode="normal"/>
   </xsl:when>
   <xsl:otherwise>
     <xsl:apply-templates/>
   </xsl:otherwise>
 </xsl:choose>
</xsl:template>

<xsl:template match="/" mode="normal">
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="node()" mode="xinclude">
  <xsl:copy
    ><xsl:call-template name="xinclude-copy-attributes"
    /><xsl:apply-templates select="node()" mode="xinclude" 
  /></xsl:copy>
</xsl:template>

<xsl:template match="xi:include" mode="xinclude">
  <xsl:variable name="xpath" select="@href"/>
  <xsl:choose>
    <xsl:when test="$xpath != ''">
      <xsl:message>Including <xsl:value-of 
      select="$xpath"/></xsl:message>
      <xsl:apply-templates 
      select="xptrf:resolve-xpointer-url(.)" mode="xinclude"/>
    </xsl:when>
    <xsl:otherwise>
      <xsl:message>Xinclude: Failed to get a value for the href= attribute 
      of xi:include element.</xsl:message>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

</xsl:stylesheet>

参考

于 2014-10-22T22:33:33.603 回答