【问题标题】:How to enable XInclude for XSLT in webstorm?如何在 webstorm 中为 XSLT 启用 XInclude?
【发布时间】:2013-11-02 14:27:12
【问题描述】:

我有这样的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 版本。

【问题讨论】:

    标签: xml xslt intellij-idea webstorm xinclude


    【解决方案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>
    

    参考文献

    【讨论】:

      猜你喜欢
      • 2015-05-31
      • 2012-07-16
      • 1970-01-01
      • 2012-06-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-10
      • 2013-02-13
      相关资源
      最近更新 更多