我正在尝试使用XSLT将传入的XML文件解析为SAP结构。我阅读了许多有关它的教程,并尝试了很多事情来使它起作用,但是有些事情并不合适。
我的输入-XML(缩短示例):
此XML文件似乎没有与之关联的任何样式信息。文档树如下所示。
<result>
<row>
<idSite>1</idSite>
<idVisit>5814001</idVisit>
<visitIp>62.225.0.0</visitIp>
<visitorId>8765462c24df752f</visitorId>
<actionDetails>
<row>
<type>action</type>
<url>
http://localhost/is-bin/INTERSHOP.enfinity/WFS/1401-B1-Site
</url>
<pageTitle>
XXX
</pageTitle>
<pageIdAction>6817739</pageIdAction>
<serverTimePretty>Feb 16, 2017 08:15:19</serverTimePretty>
<pageId>48157003</pageId>
<generationTime>41.13s</generationTime>
<timeSpent>972</timeSpent>
<timeSpentPretty>16 min 12s</timeSpentPretty>
<icon/>
<timestamp>1487232919</timestamp>
</row>
<row>
<type>search</type>
<url/>
<pageIdAction/>
<serverTimePretty>Feb 16, 2017 08:31:31</serverTimePretty>
<pageId>48176219</pageId>
<siteSearchKeyword>sc</siteSearchKeyword>
<generationTime>9.21s</generationTime>
<timeSpent>58</timeSpent>
<timeSpentPretty>58s</timeSpentPretty>
<icon>plugins/Morpheus/images/search_ico.png</icon>
<timestamp>1487233891</timestamp>
</row>
<row>
<type>search</type>
<url/>
<pageIdAction/>
<serverTimePretty>Feb 16, 2017 08:32:29</serverTimePretty>
<pageId>48177539</pageId>
<siteSearchKeyword>sc</siteSearchKeyword>
<generationTime>3.31s</generationTime>
<timeSpent>137</timeSpent>
<timeSpentPretty>2 min 17s</timeSpentPretty>
<icon>plugins/Morpheus/images/search_ico.png</icon>
<timestamp>1487233949</timestamp>
</row>
<row>
<type>search</type>
<url/>
<pageIdAction/>
<serverTimePretty>Feb 16, 2017 08:34:46</serverTimePretty>
<pageId>48180485</pageId>
<siteSearchKeyword>sc</siteSearchKeyword>
<generationTime>3.33s</generationTime>
<timeSpent>34</timeSpent>
<timeSpentPretty>34s</timeSpentPretty>
<icon>plugins/Morpheus/images/search_ico.png</icon>
<timestamp>1487234086</timestamp>
</row>
<row>
<type>action</type>
<url>
http://localhost/is-bin/INTERSHOP.enfinity/WFS/1401-B1-Site
</url>
<pageTitle>
YYY
</pageTitle>
<pageIdAction>6817739</pageIdAction>
<serverTimePretty>Feb 16, 2017 08:35:20</serverTimePretty>
<pageId>48181187</pageId>
<generationTime>37.19s</generationTime>
<timeSpent>10</timeSpent>
<timeSpentPretty>10s</timeSpentPretty>
<icon/>
<timestamp>1487234120</timestamp>
</row>
<row>
<type>search</type>
<url/>
<pageIdAction/>
<serverTimePretty>Feb 16, 2017 08:35:30</serverTimePretty>
<pageId>48181399</pageId>
<siteSearchKeyword>schlauch</siteSearchKeyword>
<generationTime>3.03s</generationTime>
<timeSpent>157</timeSpent>
<timeSpentPretty>2 min 37s</timeSpentPretty>
<icon>plugins/Morpheus/images/search_ico.png</icon>
<timestamp>1487234130</timestamp>
</row>
<row>
<type>search</type>
<url/>
<pageIdAction/>
<serverTimePretty>Feb 16, 2017 08:38:07</serverTimePretty>
<pageId>48184883</pageId>
<siteSearchKeyword>schlauch</siteSearchKeyword>
<generationTime>2.69s</generationTime>
<timeSpent>118</timeSpent>
<timeSpentPretty>1 min 58s</timeSpentPretty>
<icon>plugins/Morpheus/images/search_ico.png</icon>
<timestamp>1487234287</timestamp>
</row>
<row>
<type>search</type>
<url/>
<pageIdAction/>
<serverTimePretty>Feb 16, 2017 08:40:05</serverTimePretty>
<pageId>48187525</pageId>
<siteSearchKeyword>schlauch</siteSearchKeyword>
<generationTime>2.83s</generationTime>
<timeSpent>267</timeSpent>
<timeSpentPretty>4 min 27s</timeSpentPretty>
<icon>plugins/Morpheus/images/search_ico.png</icon>
<timestamp>1487234405</timestamp>
</row>
</actionDetails>
<goalConversions>2</goalConversions>
<siteCurrency>EUR</siteCurrency>
<siteCurrencySymbol>€</siteCurrencySymbol>
<serverDate>2017-02-16</serverDate>
<visitServerHour>8</visitServerHour>
<lastActionTimestamp>1487233709</lastActionTimestamp>
<lastActionDateTime>2017-02-16 08:28:29</lastActionDateTime>
<userId>600000|600001</userId>
<visitorType>returning</visitorType>
<visitorTypeIcon>plugins/Live/images/returningVisitor.gif</visitorTypeIcon>
<visitConverted>1</visitConverted>
<visitConvertedIcon>plugins/Morpheus/images/goal.png</visitConvertedIcon>
<visitCount>2</visitCount>
<firstActionTimestamp>1487229319</firstActionTimestamp>
<visitEcommerceStatus>abandonedCart</visitEcommerceStatus>
<visitEcommerceStatusIcon>plugins/Morpheus/images/ecommerceAbandonedCart.gif</visitEcommerceStatusIcon>
<daysSinceFirstVisit>1</daysSinceFirstVisit>
<daysSinceLastEcommerceOrder>0</daysSinceLastEcommerceOrder>
<visitDuration>4391</visitDuration>
<visitDurationPretty>1 hours 13 min</visitDurationPretty>
<searches>13</searches>
<actions>28</actions>
<referrerType>website</referrerType>
<referrerTypeName>Websites</referrerTypeName>
<referrerKeyword/>
<referrerKeywordPosition/>
<referrerSearchEngineUrl/>
<referrerSearchEngineIcon/>
<languageCode>de-de</languageCode>
<language>Language code de-de</language>
<deviceType>Desktop</deviceType>
<deviceTypeIcon>plugins/DevicesDetection/images/screens/normal.gif</deviceTypeIcon>
<deviceBrand>Unknown</deviceBrand>
<deviceModel/>
<operatingSystem>Windows 7</operatingSystem>
<operatingSystemName>Windows</operatingSystemName>
<operatingSystemIcon>plugins/DevicesDetection/images/os/WIN.gif</operatingSystemIcon>
<operatingSystemCode>WIN</operatingSystemCode>
<operatingSystemVersion>7</operatingSystemVersion>
<browserFamily>Blink</browserFamily>
<browserFamilyDescription>Blink (Chrome, Opera)</browserFamilyDescription>
<browser>Chrome 56.0</browser>
<browserName>Chrome</browserName>
<browserIcon>plugins/DevicesDetection/images/browsers/CH.gif</browserIcon>
<browserCode>CH</browserCode>
<browserVersion>56.0</browserVersion>
<events>0</events>
<continent>Europe</continent>
<continentCode>eur</continentCode>
<country>Germany</country>
<visitLocalTime>08:15:19</visitLocalTime>
<visitLocalHour>8</visitLocalHour>
<daysSinceLastVisit>0</daysSinceLastVisit>
<customVariables>
<row>
<customVariableName1>saleschannel</customVariableName1>
<customVariableValue1>SV</customVariableValue1>
</row>
<row>
<customVariableName2>xxx</customVariableName2>
<customVariableValue2>xxx</customVariableValue2>
</row>
<row>
<customVariableName3>marketsegment</customVariableName3>
<customVariableValue3>0018</customVariableValue3>
</row>
<row>
<customVariableName4>login</customVariableName4>
<customVariableValue4>standard</customVariableValue4>
</row>
</customVariables>
<resolution>1920x1095</resolution>
<plugins>pdf, flash</plugins>
<pluginsIcons>
<row>
<pluginIcon>plugins/DevicePlugins/images/plugins/pdf.gif</pluginIcon>
<pluginName>pdf</pluginName>
</row>
<row>
<pluginIcon>plugins/DevicePlugins/images/plugins/flash.gif</pluginIcon>
<pluginName>flash</pluginName>
</row>
</pluginsIcons>
<serverTimestamp>1487233709</serverTimestamp>
<serverTimePretty>09:28:29</serverTimePretty>
<serverDatePretty>Thursday, February 16, 2017</serverDatePretty>
<serverDatePrettyFirstAction>Thursday, February 16, 2017</serverDatePrettyFirstAction>
<serverTimePrettyFirstAction>08:15:19</serverTimePrettyFirstAction>
</row>
</result>
我的XSLT(也缩短了,但显示出崩溃的部分):
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:sap="http://www.sap.com/sapxsl">
<xsl:output encoding="iso-8859-1" indent="yes" method="xml" version="1.0"/>
<xsl:template match="/">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<RESULT>
<xsl:for-each select="result/row">
<VISIT>
<xsl:variable name="check1" select="name()"/>
<SERVERDATE> <xsl:value-of select="serverDate"/> </SERVERDATE>
<USERID> <xsl:value-of select="userId"/> </USERID>
<VISITORTYPE> <xsl:value-of select="visitorType"/> </VISITORTYPE>
<VISITECOMMERCESTATUS> <xsl:value-of select="visitECommerceOrder"/> </VISITECOMMERCESTATUS>
<DAYSSINCEFIRSTVISIT> <xsl:value-of select="daysSinceFirstVisit"/> </DAYSSINCEFIRSTVISIT>
<VISITDURATION> <xsl:value-of select="visitDuration"/> </VISITDURATION>
<SEARCHES> <xsl:value-of select="searches"/> </SEARCHES>
<ACTIONS> <xsl:value-of select="actions"/> </ACTIONS>
<REFERRERTYPE> <xsl:value-of select="referrerType"/> </REFERRERTYPE>
<REFERRERTYPENAME> <xsl:value-of select="referrerTypeName"/> </REFERRERTYPENAME>
<REFERRERNAME> <xsl:value-of select="referrerName"/> </REFERRERNAME>
<REFERRERKEYWORD> <xsl:value-of select="referrerKeyword"/> </REFERRERKEYWORD>
<DEVICETYPE> <xsl:value-of select="deviceType"/> </DEVICETYPE>
<xsl:for-each select="actionDetails/row">
<xsl:variable name="row" select="current()" />
<ACTIONDETAILS>
<TYPE> <xsl:value-of select="$row/type"/> </TYPE>
<URL> <xsl:value-of select="$row/url"/> </URL>
<GOALNAME> <xsl:value-of select="$row/goalName"/> </GOALNAME>
<GOALID> <xsl:value-of select="$row/goalId"/> </GOALID>
<SITESEARCHKEYWORD> <xsl:value-of select="$row/siteSearchKeyword"/> </SITESEARCHKEYWORD>
<ITEMS> <xsl:value-of select="$row/items"/> </ITEMS>
<xsl:for-each select="itemDetails/row">
<ITEMDETAILS>
<ITEMSKU> <xsl:value-of select="itemSKU"/></ITEMSKU>
<ITEMNAME> <xsl:value-of select="itemName"/></ITEMNAME>
<ITEMCATEGORY> <xsl:value-of select="itemCategory"/></ITEMCATEGORY>
<PRICE> <xsl:value-of select="price"/></PRICE>
<QUANTITY> <xsl:value-of select="quantity"/></QUANTITY>
</ITEMDETAILS>
</xsl:for-each>
</ACTIONDETAILS>
</xsl:for-each>
<CUSTOMVARIABLES>
<xsl:for-each select="customVariables/row">
<xsl:if test="contains(name(), '4' )">
<IDENTIFIER> <xsl:text> 4 </xsl:text> </IDENTIFIER>
<CUSTOMVARIABLENAME> <xsl:value-of select="customVariableName4"/> </CUSTOMVARIABLENAME>
<CUSTOMVARIABLEVALUE> <xsl:value-of select="customVariableValue4"/> </CUSTOMVARIABLEVALUE>
</xsl:if>
</xsl:for-each>
</CUSTOMVARIABLES>
<RESULT> <xsl:value-of select="result"/> </RESULT>
<MESSAGE> <xsl:value-of select="message"/> </MESSAGE>
</VISIT>
</xsl:for-each>
</RESULT>
</asx:values>
</asx:abap>
</xsl:template>
</xsl:transform>
此外,如果重要的话,我的转换呼叫:
CALL TRANSFORMATION zz_tf_xmlvisit
SOURCE XML myXml
RESULT result = myVisits.
现在问题:一旦解析器移至第二个for-loop中的第一个元素(在这种情况下为'type'),它就会崩溃,调试器将抛出cx_xslt_format_error。没有调试的情况下,只是说" XML-ABAP转换的意外文本"。
我高度认为我不知道的XSLT解析器存在一些特定的问题。如果我使用在线验证器验证转换,则可以正常工作。
得到它:
...
<DEVICETYPE> <xsl:value-of select="deviceType"/> </DEVICETYPE>
<ACTIONDETAILS>
<xsl:for-each select="actionDetails/row">
<!-- <xsl:variable name="row" select="current()" />-->
<ACTIONDETAIL>
<TYPE> <xsl:value-of select="type"/> </TYPE>
<URL> <xsl:value-of select="url"/> </URL>
<GOALNAME> <xsl:value-of select="goalName"/> </GOALNAME>
<GOALID> <xsl:value-of select="goalId"/> </GOALID>
<SITESEARCHKEYWORD> <xsl:value-of select="siteSearchKeyword"/> </SITESEARCHKEYWORD>
<ITEMS> <xsl:value-of select="items"/> </ITEMS>
<ITEMDETAILS>
<xsl:for-each select="itemDetails/row">
<ITEMDETAIL>
<ITEMSKU> <xsl:value-of select="itemSKU"/></ITEMSKU>
<ITEMNAME> <xsl:value-of select="itemName"/></ITEMNAME>
<ITEMCATEGORY> <xsl:value-of select="itemCategory"/></ITEMCATEGORY>
<PRICE> <xsl:value-of select="price"/></PRICE>
<QUANTITY> <xsl:value-of select="quantity"/></QUANTITY>
</ITEMDETAIL>
</xsl:for-each>
</ITEMDETAILS>
</ACTIONDETAIL>
</xsl:for-each>
</ACTIONDETAILS>
...
我的结构确实正确:p
我忘了为我的ActionDetail集合添加父节点ActionDetail s 。那就是为什么它毕竟是错误的节点...我没有解释为什么它在验证器中正确工作,但至少它现在正在工作。谢谢!