私は XSLT に非常に慣れていません。プロジェクトのある時点で立ち往生しています。以下の XML を取得して、目的の HTML を生成する必要があります。
サブセクション「追加」の下にある子ノードを取得し、それらを 2 つずつ HTML 行にグループ化して、各行に左要素と右要素を配置する必要があります。
適切な左右の要素を取得できます。次に、すべての子ノードを 1 つの大きな行にグループ化するか、各子ノードを個別の行にグループ化します。ただし、左要素と右要素を持つ行内に 2 つの HTML グループを作成することはできません。
show="" 属性に追加するストーリーの数を制限する必要があります。これは常に偶数の整数を返します。制限が機能しており、行数を計算できます。しかし、それらを 2 列に分割することはできません。
コピー ノードを使用する必要があることはわかっていますが、機能させることができません。
次の XML があります。
<?xml version="1.0" ?>
<fullpage>
<section name="tops">
<subsect name="featured" count="1">
<article>
<url>http://www.myurl.com</url>
<title>Title Element</title>
<description>Description</description>
<align></align>
<size>2</size>
</article>
</subsect>
<subsect name="additional" count="7" show="6">
<article>
<url>http://www.myurl.com</url>
<title>Title Element</title>
<description>Description</description>
<align>left</align>
</article>
<article>
<url>http://www.myurl.com</url>
<title>Title Element</title>
<description>Description</description>
<align>right</align>
</article>
<article>
<url>http://www.myurl.com</url>
<title>Title Element</title>
<description>Description</description>
<align>left</align>
</article>
<article>
<url>http://www.myurl.com</url>
<title>Title Element</title>
<description>Description</description>
<align>right</align>
</article>
<article>
<url>http://www.myurl.com</url>
<title>Title Element</title>
<description>Description</description>
<align>left</align>
</article>
<article>
<url>http://www.myurl.com</url>
<title>Title Element</title>
<description>Description</description>
<align>right</align>
</article>
<article>
<url>http://www.myurl.com</url>
<title>Title Element</title>
<description>Description</description>
<align>left</align>
</article>
</subsect>
</section>
<section name="section2">
<article>
...
</article>
<article>
...
</article>
<article>
...
</article>
<article>
...
</article>
</section>
</fullpage>
これまでの XSLT は次のとおりです。
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<xsl:variable name="topadd" select="fullpage/section[@name='tops']/subsect[@name='additional']/@show" />
<xsl:variable name="topaddrows" select="fullpage/section[@name='tops']/subsect[@name='additional']/@show div 2" />
<!-- top news -->
<div class="bucket">
<xsl:for-each select="fullpage/section[@name='tops']/subsect[@name='featured']">
<xsl:choose>
<xsl:when test="article/size = '2'">
<div class="col2Feature">
<ul>
<li> Two <xsl:value-of select="article/title"/> </li>
</ul>
</div>
</xsl:when>
<xsl:when test="article/size = '4'">
<div class="col4Feature">
<ul>
<li> Four <xsl:value-of select="article/title"/> </li>
</ul>
</div>
</xsl:when>
<xsl:when test="article/size = '6'">
<div class="col6Feature">
<ul>
<li> Six <xsl:value-of select="article/title"/> </li>
</ul>
</div>
</xsl:when>
<xsl:when test="article/size = '8'">
<div class="col8Feature">
<ul>
<li> Eight <xsl:value-of select="article/title"/> </li>
</ul>
</div>
</xsl:when>
</xsl:choose>
<!-- /feature -->
</xsl:for-each>
</div>
<!-- /top news -->
<xsl:value-of select="$topaddrows"/>
<xsl:for-each select="fullpage/section[@name='tops']/subsect[@name='additional']/article">
<xsl:if test="not(position() > $topadd)">
<xsl:choose>
<xsl:when test="align = 'left'">
<div class="bucketL">
<ul>
<li> <xsl:value-of select="title"/> </li>
</ul>
</div>
</xsl:when>
<xsl:when test="align = 'right'">
<div class="bucketR">
<ul>
<li> <xsl:value-of select="title"/> </li>
</ul>
</div>
</xsl:when>
</xsl:choose>
</xsl:if>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
必要な HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Document</title>
</head>
<body>
<div class="bucket">
<div class="col2Feature">
<ul>
<li> Two Title Element</li>
</ul>
</div>
</div>
<div class="col2">
<div class="bucketL">
<ul>
<li>Title Element</li>
</ul>
</div>
<div class="bucketR">
<ul>
<li>Title Element</li>
</ul>
</div>
</div>
<div class="col2">
<div class="bucketL">
<ul>
<li>Title Element</li>
</ul>
</div>
<div class="bucketR">
<ul>
<li>Title Element</li>
</ul>
</div>
</div>
<div class="col2">
<div class="bucketL">
<ul>
<li>Title Element</li>
</ul>
</div>
<div class="bucketR">
<ul>
<li>Title Element</li>
</ul>
</div>
</div>
</body>
</html>