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
不需要的元素数据(没有元素)出现在xslt中_Xslt - Fatal编程技术网

不需要的元素数据(没有元素)出现在xslt中

不需要的元素数据(没有元素)出现在xslt中,xslt,Xslt,我正在尝试应用转换来生成rdf文档。我的源xml包含一个我想忽略的元素,但输出(通过SAP的转换测试工具生成)包括SYSINFO中元素的(连接!)文本。 我尝试了几种变体(例如xsl:apply templates select=“asx:abap/asx:/values/CT”) 但是我没有得到任何输出。嗯,我花了好几个小时尝试不同的东西和研究,但一无所获。非常感谢您的帮助。约翰 这是我的示例xml(片段) sapserver06 ECC 701 00 800 XXX E 2013-04-0

我正在尝试应用转换来生成rdf文档。我的源xml包含一个我想忽略的元素,但输出(通过SAP的转换测试工具生成)包括SYSINFO中元素的(连接!)文本。
我尝试了几种变体(例如xsl:apply templates select=“asx:abap/asx:/values/CT”) 但是我没有得到任何输出。嗯,我花了好几个小时尝试不同的东西和研究,但一无所获。非常感谢您的帮助。约翰

这是我的示例xml(片段)


sapserver06
ECC
701
00
800
XXX
E
2013-04-09
12:06:58
CST
Windows NT
YYY
ZZZ
C
杰德
1.
T000
阿德纳
CHAR10
.....
这就是转变

<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:sap="http://www.sap.com/sapxsl" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:sap_coda="http://www.sapmantics.com/sap_coda#" version="1.0">

  <xsl:strip-space elements="*"/>

  <xsl:template match="/">
    <rdf:RDF>
      <xsl:apply-templates/>
    </rdf:RDF>
  </xsl:template>

  <xsl:template>
    <xsl:for-each select="//item">
      <rdf:Description>
        <xsl:attribute name="rdf:about">
          <xsl:value-of select="TABNAME"/>
        </xsl:attribute>
        <rdf:type rdf:resource="http://www.sapmantics.com/sap_coda#ctable"/>
        <sap_coda:t2f>
          <rdf:Description>
            <xsl:attribute name="rdf:about">
              <xsl:value-of select="FIELDNAME"/>
            </xsl:attribute>
            <rdf:type rdf:resource="http://www.sapmantics.com/sap_coda#cfield"/>
            <xsl:if test="KEYFLAG=X">
              <sap_coda:keyflag>X</sap_coda:keyflag>
            </xsl:if>
          </rdf:Description>
        </sap_coda:t2f>
      </rdf:Description>
    </xsl:for-each>
  </xsl:template>

</xsl:transform>

X
最后,这里是输出:

<?xml version="1.0" encoding="utf-16"?>
sapserver06ECC70100800XXXE2013-04-0917:21:50CSTWindowsNTYYYZZZCJED
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:sap_coda="http://www.sapmantics.com/sap_coda#">
<rdf:Description rdf:about="T000">
<rdf:type rdf:resource="http://www.sapmantics.com/sap_coda#ctable"/>....

sapserver06ECC70100800XXXE2013-04-0917:21:50CSTwindowsntyyyzcjed
....

可以通过元素节点的默认处理来解释
文本节点的串联:

我不知道您使用的是哪个XSLT处理器,但我很惊讶您的
//项
处理程序没有被标记为缺少
@match
属性。您可以使用以下内容更新它,它将按文档顺序处理每个
元素:

<xsl:template match="item">
    <rdf:Description>

要防止SYSINFO内容包含在RDF中(如果这是您的意图),请使用以下内容更新根模板:

<rdf:RDF>
    <xsl:apply-templates select="//item"/>
</rdf:RDF>

-----------编辑--------------------------

有了这个输入

<?xml version="1.0" encoding="utf-8"?>
<asx:abap xmlns:asx="http://www.sap.com/abapxml">
    <asx:values>
        <SYSINFO>
            <SERVER_NAME>sapserver06</SERVER_NAME>
            <SYSTEM_ID>ECC</SYSTEM_ID>
            <SAP_RELEASE>701</SAP_RELEASE>
            <SYS_NR>00</SYS_NR>
            <CLIENT>800</CLIENT>
            <EXE_USER>XXX</EXE_USER>
            <LOGON_LANGUAGE>E</LOGON_LANGUAGE>
            <DATE>2013-04-09</DATE>
            <TIME>12:06:58</TIME>
            <TIMEZONE>CST</TIMEZONE>
            <OPERATING_SYSTEM>Windows NT</OPERATING_SYSTEM>
            <LICENSE_NUMBER>YYY</LICENSE_NUMBER>
            <SAP_CUSTOMER>ZZZ</SAP_CUSTOMER>
            <CLIENT_CATEGORY>C</CLIENT_CATEGORY>
            <LANGUAGES_INSTALLED>JED</LANGUAGES_INSTALLED>
        </SYSINFO>
        <CT>
            <item>
                <ID>1</ID>
                <TABNAME>T000</TABNAME>
                <FIELDNAME>ADRNR</FIELDNAME>
                <KEYFLAG/>
                <ROLLNAME>CHAR10</ROLLNAME>
            </item>
        </CT>
    </asx:values>
</asx:abap>

sapserver06
ECC
701
00
800
XXX
E
2013-04-09
12:06:58
CST
Windows NT
YYY
ZZZ
C
杰德
1.
T000
阿德纳
CHAR10
这个样式表呢

<?xml version="1.0" encoding="UTF-8"?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:sap="http://www.sap.com/sapxsl"
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:sap_coda="http://www.sapmantics.com/sap_coda#" 
    version="1.0">

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

    <xsl:template match="/">
        <rdf:RDF>
            <xsl:apply-templates select="//item"/>
        </rdf:RDF>
    </xsl:template>

    <xsl:template match="item[parent::CT]">
        <rdf:Description>
            <xsl:attribute name="rdf:about">
                <xsl:value-of select="TABNAME"/>
            </xsl:attribute>
            <rdf:type rdf:resource="http://www.sapmantics.com/sap_coda#ctable"/>
            <sap_coda:t2f>
                <rdf:Description>
                    <xsl:attribute name="rdf:about">
                        <xsl:value-of select="FIELDNAME"/>
                    </xsl:attribute>
                    <rdf:type rdf:resource="http://www.sapmantics.com/sap_coda#cfield"/>
                    <xsl:if test="KEYFLAG=X">
                        <sap_coda:keyflag>X</sap_coda:keyflag>
                    </xsl:if>
                </rdf:Description>
            </sap_coda:t2f>
        </rdf:Description>
    </xsl:template>

    <xsl:template match="item[parent::FOO]"/> 

    <xsl:template match="item"/> 
</xsl:transform>

X
我从Saxon EE 9.4.0.3获得以下输出:

<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF xmlns:sap="http://www.sap.com/sapxsl"
         xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
         xmlns:sap_coda="http://www.sapmantics.com/sap_coda#">
   <rdf:Description rdf:about="T000">
      <rdf:type rdf:resource="http://www.sapmantics.com/sap_coda#ctable"/>
      <sap_coda:t2f>
         <rdf:Description rdf:about="ADRNR">
            <rdf:type rdf:resource="http://www.sapmantics.com/sap_coda#cfield"/>
         </rdf:Description>
      </sap_coda:t2f>
   </rdf:Description>
</rdf:RDF>

xstlproc的输出:

<?xml version="1.0"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:sap="http://www.sap.com/sapxsl" xmlns:sap_coda="http://www.sapmantics.com/sap_coda#">
  <rdf:Description rdf:about="T000">
    <rdf:type rdf:resource="http://www.sapmantics.com/sap_coda#ctable"/>
    <sap_coda:t2f>
      <rdf:Description rdf:about="ADRNR">
        <rdf:type rdf:resource="http://www.sapmantics.com/sap_coda#cfield"/>
      </rdf:Description>
    </sap_coda:t2f>
  </rdf:Description>
</rdf:RDF>


xsl:template
没有
match
name
属性是语法错误。这真的是你的代码吗?是的,迈克尔,你是对的。我检查了文件,它在for each的上方显示xsl:template match=“CT”。但这并没有改变结果。我的错——我错过了帖子中的比赛。我在匹配“item”时所关心的是,最终xml将在不同的元素下包含许多项(上面的情况只是CT)。但我想在不同的表格(如CT)中应用不同的模板。让我困惑的是匹配。我尝试了许多排列,match=/asx:abap/asx:values/e2位于较低的模板上,但没有生成任何数据。我想要的是这样的东西:。。。 ... 见上面修订版中的输出。不知道为什么你会看到不同的结果。
<?xml version="1.0"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:sap="http://www.sap.com/sapxsl" xmlns:sap_coda="http://www.sapmantics.com/sap_coda#">
  <rdf:Description rdf:about="T000">
    <rdf:type rdf:resource="http://www.sapmantics.com/sap_coda#ctable"/>
    <sap_coda:t2f>
      <rdf:Description rdf:about="ADRNR">
        <rdf:type rdf:resource="http://www.sapmantics.com/sap_coda#cfield"/>
      </rdf:Description>
    </sap_coda:t2f>
  </rdf:Description>
</rdf:RDF>