Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.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
Debugging 带有xsl:attribute set元素的XSLT简化样式表_Debugging_Xslt_Attributes_Declaration_Xml Literals - Fatal编程技术网

Debugging 带有xsl:attribute set元素的XSLT简化样式表

Debugging 带有xsl:attribute set元素的XSLT简化样式表,debugging,xslt,attributes,declaration,xml-literals,Debugging,Xslt,Attributes,Declaration,Xml Literals,我试图在xsl文档中使用,但不断收到错误消息: 编译错误:第47行元素属性集 元素属性集仅允许作为样式表的子级 我还查阅了W3Schools网站上的解释,发现: Must be child of <xsl:stylesheet> or <xsl:transform>. 下面是在问题中添加XSLT开始之前编写的。它没有解决问题的性质。迈克尔·凯的回答确实如此 xsl:attribute set必须是xsl:stylesheet元素的子元素,它是XSLT的根元素。这与x

我试图在xsl文档中使用
,但不断收到错误消息:

  • 编译错误:第47行元素属性集
  • 元素属性集仅允许作为样式表的子级
我还查阅了W3Schools网站上的解释,发现:

Must be child of <xsl:stylesheet> or <xsl:transform>.

下面是在问题中添加XSLT开始之前编写的。它没有解决问题的性质。迈克尔·凯的回答确实如此

xsl:attribute set
必须是
xsl:stylesheet
元素的子元素,它是XSLT的根元素。这与
xsl:output
xsl:template
相同

将这些元素描述为“顶级元素”类别

w3schools.com从几个方面说明了这一点:

  • ELMENT是一个顶级元素
  • 必须是或的孩子
  • 元素是顶级元素,必须显示为或的子节点
范例

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

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

    <xsl:attribute-set name="body-attr">
        <xsl:attribute name="color">red</xsl:attribute>
    </xsl:attribute-set>

    <xsl:template match="/">
        <xsl:element name="result" use-attribute-sets="body-attr">
        </xsl:element>
    </xsl:template>

</xsl:stylesheet>

红色

您使用的是非常罕见的功能,也称为“简化样式表”,其中
xsl:stylesheet
元素和最外层的
xsl:template
是隐式的。你的问题说明了为什么这个设施很少使用——它很快就会耗尽蒸汽。因为没有
xsl:stylesheet
元素,所以
xsl:stylesheet
的常规子元素都不存在,这包括属性集的声明


更改代码以将其包装在显式的
xsl:stylesheet
xsl:template match=“/”
中。然后在与
xsl:template

相同的级别添加
xsl:attribute set
,另一种使用简化语法的方法是将xmlns从
html
标记中移出,然后通过
document
函数内联源文件:

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

    <blockquote>
        <xsl:for-each select="document('movies.xml')//processing-instruction()[contains(., '2014')]">
            <p><xsl:value-of select="concat( local-name(),' ', current() )"/></p>

            <a href="{substring-before(document('movies.xml')//processing-instruction(),',')}">
                <input type="button" value="Stream {local-name()}"/>
            </a>

            <a href="{substring-after(document('movies.xml')//processing-instruction(),',')}">
                <input type="button" value="{local-name()} Soundtrack"/>                    
            </a>

        </xsl:for-each>            
    </blockquote>

 </section>

然后包括:

<stylesheet version="1.0" xmlns="http://www.w3.org/1999/XSL/Transform">
    <include href="simple.xsl"/>
    <attribute-set name="foo"></attribute-set>
    <apply-templates/>
</stylesheet>



编辑您的帖子,使其包含样式表的前10行左右(使用编辑器中的
{}
按钮格式化XML代码)。我只添加了前2行,因为它们是相关的。。。在这之后,它只是一个for-each循环来选择数据。我明白了,当你们提到child时,并没有嵌套?它必须是“直接”的孩子?事实上,不,你不能。它必须是孩子,不能是后代。我想我会为这个亲子问题打另一个问题。谢谢你的帮助。干杯,我认为这是一个更合适的答案。
<?xml version="1.0" encoding="UTF-8"?>
 <section
  xsl:version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns=""
 >

    <blockquote>
        <xsl:for-each select="document('movies.xml')//processing-instruction()[contains(., '2014')]">
            <p><xsl:value-of select="concat( local-name(),' ', current() )"/></p>

            <a href="{substring-before(document('movies.xml')//processing-instruction(),',')}">
                <input type="button" value="Stream {local-name()}"/>
            </a>

            <a href="{substring-after(document('movies.xml')//processing-instruction(),',')}">
                <input type="button" value="{local-name()} Soundtrack"/>                    
            </a>

        </xsl:for-each>            
    </blockquote>

 </section>
<stylesheet version="1.0" xmlns="http://www.w3.org/1999/XSL/Transform">
    <include href="simple.xsl"/>
    <attribute-set name="foo"></attribute-set>
    <apply-templates/>
</stylesheet>