首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在样式表编译过程中报告了XSLT 2错误。

在样式表编译过程中报告了XSLT 2错误。
EN

Stack Overflow用户
提问于 2021-06-18 17:21:12
回答 2查看 501关注 0票数 0

我有以下XML文件:

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>
<contentSet>
    <inlineXML contenttype="application/xhtml+xml" xml:lang="en">
        <html xmlns="http://www.w3.org/1999/xhtml">
            <head>
                <title/>
            </head>
            <body>
                <p>EDITORS PLEASE NOTE, RESENDING TO CHANGE CERTAIN LOCATIONS FROM MOGADISHU, SOMALIA TO NAIROBI, KENYA.</p>
                <p>Years of conflict, and the threat of al Qaeda-linked Islamists battling to overthrow the government, leave many Somalis dependent on aid.  But an application called e-Shop has changed that dynamic says the World Food Programme.</p>
                <p>SHOWS: MOGADISHU, SOMALIA (RECENT) (REUTERS - ACCESS ALL)</p>
                <p>1. VARIOUS OF STOREKEEPER DISPATCHING ORDERS</p>
                <p>2. MAN CARRYING ORDER TO A WAITING DELIVERY TRUCK</p>
                <p>3. DELIVERY TRUCK ARRIVING AT AN IDP (INTERNALLY DISPLACED PERSONS) CAMP</p>
                <p>4. MAN OFFLOADING DELIVERIES AS WORLD FOOD PROGRAMME (WFP) SUPERVISORS LOOK ON</p>
                <p>5. VARIOUS OF MUSLIMA ABDIRAHMAN AND HER CHILDREN AT THEIR HOME</p>
                <p>6. (SOUNDBITE) (Somali) MUSLIMA ABDIRAHMAN, E-SHOP USER, SAYING:</p>
                <p>"It has become dangerous to go to the shops because we are afraid of catching the coronavirus. We were lucky to get this application. We enjoy online shopping; it also saves time and we get the food we want"</p>
                <p>7. VARIOUS OF WFP TECHNICIAN HELPING A WOMAN MANAGE HER ACCOUNT ON THE "E-SHOP" APPLICATION</p>
                <p>8. VARIOUS OF ILHAN MOHAMED GIVING BREAKFAST TO HER CHILDREN AT HOME</p>
                <p>9. ILHAN PLAYING WITH HER BABY</p>
                <p>10. (SOUNDBITE) (Somali) ILHAN MOHAMED, E-SHOP USER, SAYING:</p>
                <p>"I order food that I need on the day such as rice or spaghetti. The delivery team brings the food to my home and the shop owner withdraws the money from my card."</p>
                <p>NAIROBI, KENYA (RECENT) (REUTERS - ACCESS ALL)</p>
                <p>11. VARIOUS OF CESAR ARROYO, COUNTRY DIRECTOR, WFP SOMALIA</p>
                <p>12. (SOUNDBITE) (English) CESAR ARROYO, COUNTRY DIRECTOR, WFP SOMALIA:</p>
                <p>“The e-Shop is a system that if it works in Somalia, it can work anywhere else. Somalia offers all the challenges that can actually be the testing ground for a system like this.”</p>
                <p>MOGADISHU, SOMALIA (RECENT) (REUTERS - ACCESS ALL)</p>
                <p>13. VARIOUS OF MUSLIMA AND ILHAN SITTING WITH THEIR CHILDREN UNDER A TREE</p>
                <p>NAIROBI, KENYA (RECENT) (REUTERS - ACCESS ALL)</p>
                <p>14. (SOUNDBITE) (English) CESAR ARROYO, COUNTRY DIRECTOR, WFP SOMALIA:</p>
                <p>“Many years ago when we were handing food, the people accept the food but you could see in their body language how the dignity wasn’t there because when you are receiving food you are without the opportunity of discussing or challenge, you don’t have that strength and you can see the body language of these beneficiaries have changed now tremendously because now with the cash base assistance that we provide, they are the ones deciding where and what to buy.”</p>
                <p>MOGADISHU, SOMALIA (RECENT) (REUTERS - ACCESS ALL)</p>
                <p>15. E-SHOP REPRESENTATIVE SHOWING IDP HOW TO USE THE APP</p>
                <p>16. VARIOUS OF PEOPLE AT IDP CAMP</p>
                <p>17. CHILDREN AT THE CAMP</p>
                <p>STORY: Muslima Abdirahman, a Somali mother of nine, escaped death twice in the past two years while shopping for groceries in the city of Mogadishu, where Islamist insurgents regularly carry out suicide bombings on busy streets and markets.</p>
                <p>She traded the dangerous errand for online shopping earlier this year, thanks to the World Food Programme's "humanitarian e-commerce" system in Somalia -- part of its global shift from giving out food to cash.</p>
                <p>Originally conceived as a way to protect women in Somalia from security threats -- be it bombings in the capital or harassment in a camp -- it is also helping avoid large crowds at aid distribution sites during the COVID-19 pandemic.</p>
                <p>Abdirahman compares the prices of products like cooking oil and salt offered by retailers on an app called e-Shop created by WFP, spending the $60 stipend she receives from the agency as she sees fit. This frees time for working as a cleaner and childcare, she said.</p>
                <p>"It has become dangerous to go to the shops because we are afraid of catching the coronavirus. We were lucky to have this application. We enjoy online shopping; it also saves time and we get the food we want."</p>
                <p>Her neighbour Ilhan Adow, who also uses the WFP app, says she uses the hours she saves to breastfeed her children, do chores and rest.</p>
                <p>"I order food that I need on the day such as rice or spaghetti. The delivery team brings the food to my home and the shop owner withdraws the money from my card," Adow said.</p>
                <p>Though WFP launched e-Shop in 2018, it introduced home delivery in April, the month after COVID-19 hit Somalia.</p>
                <p>Years of conflict, and the threat of al Qaeda-linked Islamists battling to overthrow the government, leave many Somalis dependent on aid.</p>
                <p>But e-Shop has changed the dynamic, said Cesar Arroyo, head of WFP in the country.</p>
                <p>“Years ago, when we were handing out food, people accepted it but you could see in their body language how the dignity wasn’t there,” he said. “Now…they are the ones deciding where and what to buy.”</p>
                <p>Hundreds of retailers sell on the app. Transactions are recorded to comply with the government tax system. Purchases are verified on delivery using biometrics.</p>
                <p>Six million dollars in transactions, and more than 51,000 deliveries, have gone through the system.</p>
                <p>It operates in Mogadishu, including in camps for people forced from their homes by violence, and in all Somalia’s main towns.</p>
                <p>WFP has long used electronic vouchers for distributing cash aid for Syrian refugees, but Somalia is the first place where it has used an app and home delivery system.</p>
                <p>The U.N. agency, which won the Nobel Peace Prize this year, hopes to roll out online shopping elsewhere, said Arroyo. “If it works in Somalia it can work anywhere else.”</p>
                <p>Nearly 100,000 out of the 500,000 people receiving cash aid monthly from the U.N. in Somalia are using e-Shop. The number of app users recently shot up, from 47,000 at the end of March, before home delivery launched, to 94,000 at the end of October.</p>
            </body>
        </html>
    </inlineXML>
</contentSet>

我想检索<body></body>之间的所有内容。我需要保存<p></p>

以下是我的XSL文件:

代码语言:javascript
复制
    <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns0="http://iptc.org/std/nar/2006-10-01/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" exclude-result-prefixes="ns0 xs fn">
    <xsl:output method="xml" encoding="UTF-8" byte-order-mark="no"/>
    <xsl:template match="/">
        
        <xsl:variable name="var1_map_of_newsMessage" as="xs:string*">
            <xsl:for-each select="ns0:contentSet/ns0:inlineXML/ns1:html/ns1:body">
                <xsl:sequence select="fn:string(.)"/>
            </xsl:for-each>
        </xsl:variable>

        <xsl:variable name="body_content">       
            <xsl:sequence select="($var1_map_of_newsMessage)[(fn:position() = xs:integer('1'))]"/>      
        </xsl:variable> 

        <xsl:element name="body">
            <xsl:value-of select="$body_content"/>
        </xsl:element>
    </xsl:template>
</xsl:stylesheet>

在进行翻译时,我得到了这样的信息:无法使用提供的XML/XSL输入生成XML文档。在样式表编译期间报告了错误。

知道我怎么能做到这一点吗?我到处寻找,用阿尔托瓦地图来帮助我,但似乎没有任何效果。谢谢你抽出时间看我的帖子。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2021-06-21 18:04:56

,我想检索<body></body>之间的所有内容。我需要保存<p></p>

你为什么不能简单地做:

代码语言:javascript
复制
<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:x="http://www.w3.org/1999/xhtml"
exclude-result-prefixes="x">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>

<xsl:template match="/contentSet">
    <xsl:copy-of select="inlineXML/x:html/x:body"/>
</xsl:template>

</xsl:stylesheet>

或者,如果您不想保留名称空间:

代码语言:javascript
复制
<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:x="http://www.w3.org/1999/xhtml"
exclude-result-prefixes="x">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>

<xsl:template match="/contentSet">
    <xsl:apply-templates select="inlineXML/x:html/x:body"/>
</xsl:template>

<xsl:template match="*">
    <xsl:element name="{local-name()}">
        <xsl:copy-of select="@*"/>
        <xsl:apply-templates/>
    </xsl:element>
</xsl:template>

</xsl:stylesheet>
票数 0
EN

Stack Overflow用户

发布于 2021-06-18 22:22:20

首先,Errors were reported during stylesheet compilation的意思是它所说的。在某个地方有一条详细的错误消息,但是您没有看到它,因为它已经被记录或报告到某个您看不到的目的地。您需要了解如何调用样式表编译(通过API或命令行),以及在哪里引导错误消息。

将样式表粘贴到氧气中将立即显示错误“名称空间前缀'ns1‘尚未声明”。但是你上面的评论说你发布的代码不是你真正的代码(这让我很想知道你为什么要发布它),如果你不发布你的真实代码,我们就不能告诉你它到底出了什么问题。

一旦要编译样式表,其逻辑中就会出现一些错误:

  • 变量var1_map_of_newsMessage将包含一个字符串,因为只有一个body元素。我想你可能想为每一段找一个字符串。或者您可能想要段落元素本身,因为您说要保留标记。

您可以用谓词[1].替换谓词[(fn:position() = xs:integer('1'))]

  • -- bodyContent的变量声明--正在创建大量数据的不必要副本。为了避免复制,要么(a)声明变量类型as="node()*",要么(b)使用带有select属性的xsl:variable元素,而不使用子元素。
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68039209

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档