gpt4 book ai didi

没有架构的 sharepoint 数据 View web 部件 xslt

转载 作者:行者123 更新时间:2023-12-04 06:57:30 24 4
gpt4 key购买 nike

我正在尝试使用数据 View Web 部件(通过 SPD 2007)来使用基于 SOAP 的 Web 服务的结果并使用 XSL 转换呈现部分所述结果。我遇到的问题是设计器没有太大帮助,因为 Web 服务的架构实际上并不包含结果的元素,因此无法从数据源拖放到 Web 部件中,并且我尝试的手动转换不起作用。

以下是 Web 服务的定义:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetQuote xmlns="http://www.webserviceX.NET/">
<symbol>string</symbol>
</GetQuote>
</soap:Body>
</soap:Envelope>

以及响应的定义:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetQuoteResponse xmlns="http://www.webserviceX.NET/">
<GetQuoteResult>string</GetQuoteResult>
</GetQuoteResponse>
</soap:Body>
</soap:Envelope>

查询定义没有问题 - 您只需提供一个股票代码作为字符串。不过,您会在结果中看到我在说什么。它将结果定义为一个字符串。

在SPD2007中,数据源几乎只包括 soap:Envelope/soap:Body/GetQuoteResponse/GetQuoteResult ,但结果字符串中包含的实际结果如下所示:
<StockQuotes>
<Stock>
<Symbol>MSFT</Symbol>
<Last>28.465</Last>
<Date>3/3/2010</Date>
<Time>1:24pm</Time>
<Change>+0.005</Change>
<Open>28.52</Open>
<High>28.61</High>
<Low>28.35</Low>
<Volume>28380812</Volume>
<MktCap>249.7B</MktCap>
<PreviousClose>28.46</PreviousClose>
<PercentageChange>+0.02%</PercentageChange>
<AnnRange>14.87 - 31.50</AnnRange>
<Earns>1.815</Earns>
<P-E>15.68</P-E>
<Name>Microsoft Corpora</Name>
</Stock>
</StockQuotes>

我已经尝试在数据 View Web 部件中设置这样的 XSL 样式表:
<xsl:stylesheet xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ddw1="http://www.webserviceX.NET/"
version="1.0"
exclude-result-prefixes="xsl msxsl ddwrt"
xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime"
xmlns:asp="http://schemas.microsoft.com/ASPNET/20"
xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:SharePoint="Microsoft.SharePoint.WebControls"
xmlns:ddwrt2="urn:frontpage:internal">
<xsl:output method="html" indent="yes"/>
<xsl:param name="dvt_apos">'</xsl:param>
<xsl:template match="/soap:Envelope/soap:Body/ddw1:GetQuoteResponse">
<xsl:value-of select="*" />
</xsl:template>
</xsl:stylesheet>

这与您期望的非常相似:它呈现整个结果字符串。但是,如果我更换
<xsl:template match="/soap:Envelope/soap:Body/ddw1:GetQuoteResponse">
<xsl:value-of select="*" />
</xsl:template>


<xsl:template match="/soap:Envelope/soap:Body/ddw1:GetQuoteResponse">
<xsl:value-of select="//Symbol" />
</xsl:template>

我什么也得不到。这是怎么回事?如何使用 XSL 在没有架构的情况下挑选字符串结果中的 XML?

最佳答案

在看service you are using它确实返回带有 < 的字符串中的值,使其看起来像 XML。我无法想象他们为什么会这样做,但是您需要将字符串解析为 XML 才能对其进行处理。没有原生 XSLT 函数可以执行此操作,因此您必须使用扩展函数。我不知道微软的一个,所以你必须自己写。

幸好有good example in this post这个确切的问题。此人最终使用了用 c# 编写的自定义扩展函数将字符串转换为 XML,然后将其传递回 XSLT 进行常规处理。他们使用的自定义函数是:

<msxml:script language="CSharp" implements-prefix="cd">
<msxml:using namespace="System.IO" />

public XPathNodeIterator parse(string data) {
if(data==null || data.Length==0) {
data="&lt;Empty /&gt;";
}
StringReader stringReader = new StringReader(data);
XPathDocument xPathDocument = new XPathDocument(stringReader);
XPathNavigator xPathNavigator = xPathDocument.CreateNavigator();
XPathExpression xPathExpression = xPathNavigator.Compile("/");
XPathNodeIterator xPathNodeIterator = xPathNavigator.Select(xPathExpression);
return xPathNodeIterator;
}
</msxml:script>

然后你在你的字符串上调用函数:
<xsl:variable name="theXML" select="string(/string)" />
<xsl:variable name="list" select="cd:parse($theXML)" />

我不能保证自定义函数会按照您需要的方式工作,但希望它能让您接近。

关于没有架构的 sharepoint 数据 View web 部件 xslt,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2374418/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com