开发者

XSLT for-each failing to pick up fields

开发者 https://www.devze.com 2023-01-30 18:14 出处:网络
I\'ve got a curious item, I\'m trying to enumerate through an xml file with my XSLT transform, however I\'m after putting a for-each loop into the code my records are not pulling any details (anymore)

I've got a curious item, I'm trying to enumerate through an xml file with my XSLT transform, however I'm after putting a for-each loop into the code my records are not pulling any details (anymore). Help!

XSLT

    <?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="html" indent="yes" omit-xml-declaration="yes"/>
    <xsl:variable name="pathid" select="montage/path" />
    <xsl:variable name="outputstr" select="''" />
    <xsl:template match="vista">
        <xsl:variable name="pathid" select="path" />
        <html>
            <body>
                <div align="center">
                    <table border="0" cellpadding="0" cellspacing="0" width="800" height="200">
                        <xsl:apply-templates select="item" />
                    </table>
                </div>
            </body>
        </html>
    </xsl:template>
    <xsl:template match="item">
        <xsl:variable name="monid" select="mon" />
            <!--<xsl:value-of select="format-number(position(), '#')" />-->
        <xsl:variable name="outputstr" select="file" />
            <xsl:choose>
                <xsl:when test="position() >= 0 and 4 > position()">
                    <tr height="200">
                    <xsl:for-each select="item">
                        <td width="157" height="108" valign="top">
                            <xsl:attribute name="height">
                                <xsl:value-of select="'200'"/>
                            </xsl:attribute>
                            <a>
                                <xsl:attribute name="href">
                                    <xsl:value-of select="$pathid" />
                                    <xsl:value-of select="thepage" />
                                </xsl:attribute>
                                <img>
                                    <xsl:attribute name="src">
                                        <xsl:value-of select="concat(substring-before($outputstr,'abc'),$pathid)"/>
                                        <xsl:value-of select="$outputstr" />
                                    </xsl:attribute>
         开发者_运维知识库                       </img>
                            </a>
                        </td>
                        </xsl:for-each>
                    </tr>
                </xsl:when>
            </xsl:choose>
            <xsl:attribute name="id">mon</xsl:attribute>
    </xsl:template>
</xsl:stylesheet>

XML

<?xml version="1.0"?>
<vista>
    <lastupdate>14/12/2010 14:32</lastupdate>
    <path>C:\</path>
    <item>
        <thepage>00000657.html</thepage>
        <heading>heading1</heading>
        <file>test123.png</file>
        <description>df bhdf hdfhdf hdfh he rher herh df bdf bdfb df rfbd bd</description>
    </item>
    <item>
        <thepage>00000660.html</thepage>
        <heading>heading2</heading>
        <file>test456.jpg</file>
        <description>reh erh erherh erh erher herh</description>
    </item>
</vista>

Outputted HTML

<html>
<body>
<div align="center">
<table border="0" cellpadding="0" cellspacing="0" width="800" height="200">
<tr height="200"></tr>
<tr height="200"></tr>
<tr height="200"></tr>
<tr height="100"></tr>
<tr height="100"></tr>
<tr height="100"></tr>
<tr height="100"></tr>
</table>
</div>
</body>
</html>


The line <xsl:for-each select="item"> - I think you're already in "item". You can't select it again.


You already have an item template - why do you need to for-each inside it?

I expect this to fail, as item nodes do not contain item nodes.

0

精彩评论

暂无评论...
验证码 换一张
取 消