在函数输出中查找项目
我有两个函数:
GetHomeXml() -> returns a collection of pages with a custom meta type
SiteMapXml() -> standard sitemap xml
SiteMapXml() 有一个属性 (isCurrent),如果页面是当前页面,则返回该属性。我需要确定页面名称是否出现在 GetHomeXml() 中,以及 GetHomeXml() 中的节点是否分配有 Image.FileName 属性。
我可以将两者都返回,但我无法找出 XSL 来完成此操作。以下是我到目前为止所做的:
<xsl:param name="currentPage" select="/in:inputs/in:result[@name='SitemapXml']/Page/@iscurrent" />
<xsl:for-each select="/in:inputs/in:result[@name='GetHomeXml']/Image">
<xsl:if test="@Image.PageTitle = $currentPage.Title">
<img src="@Image.FileName" />
</xsl:if>
</xsl:for-each>
我创建了一个自定义元数据条目,并向其中添加了 3 个字段 {IsTab、Image、Color}。我想确定当前页面是否包含 Image 字段,并且分配给它的 Page.Title 与当前页面相同,以呈现指定的图像(它是一个数据引用字段,具有图像查找属性) images 目录)到标签中。
但这段代码似乎没有返回任何东西?
更新:
GetHomeXml() 返回的 XML 如下:
<!-- Function Call Result (0 ms), XPath /in:inputs/in:result[@name='GetHomeXml']/IsTab -->
<in:result name="GetHomeXml">
<IsTab Id="9eba448e-9a30-478e-81b2-530bc7da2545" IsTab="true" BackgroundImg="MediaArchive:34f9be39-8273-4960-8cc6-e6b76f34e6ac" BackgroundImg.FileName="home-group-2.png" PageId.Title="Contact Us" xmlns=""/>
<IsTab Id="a46e2e98-ffcd-4675-8840-389d1a7f46ca" IsTab="true" PageId.Title="Welcome" xmlns=""/>
<IsTab Id="c76fa101-8c63-46e2-9431-e18ce875866d" IsTab="false" PageId.Title="What we do" xmlns=""/>
我想根据当前页面 (PageId.Title) 获取图像的名称,我需要匹配返回的SiteMapXml 中与当前页面关联的值:
<!-- Function Call Result (0 ms), XPath /in:inputs/in:result[@name='SitemapXml']/Page -->
<in:result name="SitemapXml">
<Page Id="62c66cb6-b2ec-4469-b0d7-54bc61b22c20" Title="Home" MenuTitle="Home" UrlTitle="Home" Description="Default web site for... Please do not change any of the settings for this site. Add, modify and delete pages underneath this web site, but do no touch this site." ChangedDate="2011-12-04T22:36:33.2651194+02:00" ChangedBy="admin" URL="/Home/c1mode(unpublished)" Depth="1" xmlns="">
<Page Id="041c7d66-60cd-4098-ac98-728c0db111a1" Title="Welcome" MenuTitle="Welcome" UrlTitle="Welcome" Description="" ChangedDate="2011-12-04T22:38:06.2815949+02:00" ChangedBy="admin" URL="/Home/Welcome/c1mode(unpublished)" Depth="2"/>
<Page Id="8ae4d8a5-f4d9-43ed-85de-90b6d3a6f0b8" Title="Contact Us" MenuTitle="Contact Us" UrlTitle="Contact-Us" Description="" ChangedDate="2011-12-04T22:54:10.1503871+02:00" ChangedBy="admin" URL="/Home/Contact-Us/c1mode(unpublished)" isopen="true" iscurrent="true" Depth="2"/>
<Page Id="ed5560a4-140b-4851-ac19-5ddc6c66a770" Title="What we do" MenuTitle="What we do" UrlTitle="What-we-do" Description="" ChangedDate="2011-11-28T07:23:25.8851421+02:00" ChangedBy="admin" URL="/Home/What-we-do/c1mode(unpublished)" Depth="2"/>
</Page>
</in:result>
</in:result>
I have two functions:
GetHomeXml() -> returns a collection of pages with a custom meta type
SiteMapXml() -> standard sitemap xml
SiteMapXml() has a property (isCurrent) that gets returned if the page is the current page. I need to determine if the name of the page appears in GetHomeXml(), and whether the node in GetHomeXml() has an Image.FileName property assigned to it.
I can get both returned, but I cannot figure out the XSL to accomplish this. Following is what I have so far:
<xsl:param name="currentPage" select="/in:inputs/in:result[@name='SitemapXml']/Page/@iscurrent" />
<xsl:for-each select="/in:inputs/in:result[@name='GetHomeXml']/Image">
<xsl:if test="@Image.PageTitle = $currentPage.Title">
<img src="@Image.FileName" />
</xsl:if>
</xsl:for-each>
I created a custom meta data entry, and added 3 fields to it {IsTab, Image, Color}. I want to determine that if the current page contains an Image field, and the Page.Title assigned to it, is the same as the current page, to render the designated image (it's a data reference field, with an image lookup property to the images directory) into the tag.
But this code does not seem to return anything?
Update:
The XML that is returned for GetHomeXml() is as follows:
<!-- Function Call Result (0 ms), XPath /in:inputs/in:result[@name='GetHomeXml']/IsTab -->
<in:result name="GetHomeXml">
<IsTab Id="9eba448e-9a30-478e-81b2-530bc7da2545" IsTab="true" BackgroundImg="MediaArchive:34f9be39-8273-4960-8cc6-e6b76f34e6ac" BackgroundImg.FileName="home-group-2.png" PageId.Title="Contact Us" xmlns=""/>
<IsTab Id="a46e2e98-ffcd-4675-8840-389d1a7f46ca" IsTab="true" PageId.Title="Welcome" xmlns=""/>
<IsTab Id="c76fa101-8c63-46e2-9431-e18ce875866d" IsTab="false" PageId.Title="What we do" xmlns=""/>
I want to get the name of the image, based on the current page (PageId.Title) I need to match back to the returned value associated with the current page in SiteMapXml:
<!-- Function Call Result (0 ms), XPath /in:inputs/in:result[@name='SitemapXml']/Page -->
<in:result name="SitemapXml">
<Page Id="62c66cb6-b2ec-4469-b0d7-54bc61b22c20" Title="Home" MenuTitle="Home" UrlTitle="Home" Description="Default web site for... Please do not change any of the settings for this site. Add, modify and delete pages underneath this web site, but do no touch this site." ChangedDate="2011-12-04T22:36:33.2651194+02:00" ChangedBy="admin" URL="/Home/c1mode(unpublished)" Depth="1" xmlns="">
<Page Id="041c7d66-60cd-4098-ac98-728c0db111a1" Title="Welcome" MenuTitle="Welcome" UrlTitle="Welcome" Description="" ChangedDate="2011-12-04T22:38:06.2815949+02:00" ChangedBy="admin" URL="/Home/Welcome/c1mode(unpublished)" Depth="2"/>
<Page Id="8ae4d8a5-f4d9-43ed-85de-90b6d3a6f0b8" Title="Contact Us" MenuTitle="Contact Us" UrlTitle="Contact-Us" Description="" ChangedDate="2011-12-04T22:54:10.1503871+02:00" ChangedBy="admin" URL="/Home/Contact-Us/c1mode(unpublished)" isopen="true" iscurrent="true" Depth="2"/>
<Page Id="ed5560a4-140b-4851-ac19-5ddc6c66a770" Title="What we do" MenuTitle="What we do" UrlTitle="What-we-do" Description="" ChangedDate="2011-11-28T07:23:25.8851421+02:00" ChangedBy="admin" URL="/Home/What-we-do/c1mode(unpublished)" Depth="2"/>
</Page>
</in:result>
</in:result>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要循环遍历结果集,而是使用 xpath 谓词按标题匹配页面。例如,欢迎页面的 URL 如下所示:
这是一个完整的 XSLT,它显示了 HomeXML 页面的 URL:
对应的 XsltCake (类似 JsFiddle,但用于 Xslt)
Instead of looping through the resultset, use a xpath predicate to match the page by title. For example, the URL of the welcome page would be given by:
Here is a complete XSLT which shows the URLs for the HomeXML pages:
Corresponding XsltCake (like JsFiddle, but for Xslt)