我是XSLT的新手,在尝试格式化具有递归节点的XML文档时遇到了一些问题.
我的XML代码:
希望我的XML显示:
<item>都嵌套着<items><item>嵌套节点的级别可能非常深<?xml version="1.0" encoding="utf-8" ?>
- <items>
<item groupID="1" name="Home" url="//" />
- <item groupID="2" name="Guides" url="/Guides/">
- <items>
- <item groupID="26" name="Online-Poker-Guide" url="/Guides/Online-Poker-Guide/">
- <items>
- <item>
<id>107</id>
- <title>
- <![CDATA[ Poker Betting - Online Poker Betting Structures
]]>
</title>
- <url>
- <![CDATA[ /Guides/Online-Poker-Guide/online-poker-betting-structures
]]>
</url>
</item>
- <item>
<id>114</id>
- <title>
- <![CDATA[ Beginners' Poker - Poker Hand Ranking
]]>
</title>
- <url>
- <![CDATA[ /Guides/Online-Poker-Guide/online-poker-hand-ranking
]]> …Run Code Online (Sandbox Code Playgroud) 我有以下XSLT
<xsl:param name="productsId" select="/macro/productsId" />
<xsl:param name="type" select="/macro/type" /> <!-- value1, value2, value3 -->
<xsl:template match="/">
<xsl:if test="$productsId > 0">
<xsl:variable name="products" select="umbraco.library:GetXmlNodeById($productsId)" />
<div id="carousel-wrap">
<ul id="carousel">
<xsl:for-each select="$products/Product [select only Product with attribute value1, value2 or value3 based on /macro/type]">
<li id="p-{@id}">
<xsl:variable name="title">
<xsl:choose>
<xsl:when test="string-length(productHeading) > 0">
<xsl:value-of select="productHeading" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@nodeName" />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<a href="{umbraco.library:NiceUrl(@id)}">
<!-- Image -->
<xsl:if test="productImage > 0">
<xsl:variable name="productImage" select="umbraco.library:GetMedia(productImage, 0)" />
<img src="/ImageGen.ashx?image={$productImage/umbracoFile}&height=131" />
</xsl:if> …Run Code Online (Sandbox Code Playgroud)