Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html xml需要浏览器对其进行解码_Html_Xml_Xslt_Cdata - Fatal编程技术网

Html xml需要浏览器对其进行解码

Html xml需要浏览器对其进行解码,html,xml,xslt,cdata,Html,Xml,Xslt,Cdata,我对if语句有问题 浏览器未解码该文件 也就是说,它不是在换行,而是在显示 在浏览器上 我也使用了CData,但它不起作用 谁能帮帮我吗 <table border="1"> <tr> <xsl:for-each select="/catalogue/item"> <td> <img src="{img/.}" alt="{img/@alt}" class="imgs-catalogue" title="click for

我对if语句有问题 浏览器未解码该文件 也就是说,它不是在换行,而是在显示 在浏览器上 我也使用了CData,但它不起作用 谁能帮帮我吗

<table border="1">
<tr>

<xsl:for-each select="/catalogue/item">

    <td>
    <img src="{img/.}" alt="{img/@alt}" class="imgs-catalogue" title="click for description"/><br/>
    Id: <xsl:value-of select="id/."/><br/>
    Name: <xsl:value-of select="name/."/><br/>
    Type: <xsl:value-of select="type/."/><br/>
    Price: <xsl:value-of select="price/text()"/><br/><br/>
    </td>       

    <xsl:if test="(position() mod 4)=0">
        </tr><tr>
    </xsl:if>

</xsl:for-each>
</tr>
</table>
这是完整的xml

 <?xml version="1.0" encoding="utf-8" ?>
 <?xml-stylesheet  type="text/xsl" href="catalogue.xsl" ?>
 <catalogue xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:noNameSpaceSchemaLocation="catalogue.xsd">

<!-- Item 1 -->
<item>
    <id>45</id>
    <name>Ginkgo Plus</name>
    <img alt="Ginkgo Plus">images/catalogueImg/ginkgo.jpg</img>
    <price>MUR 575</price>
    <type>Health</type>
    <description>
        A mixture of 3 chineese plant including ginkgo biloba and reishi.
        Many traditional medicines identifies that the leaves of the ginkgo biloba 
        have a positive effect on the circulatory system. The reishi is a champion
        used in chineese and japaneese traditional medicines to protect against 
        heart problems.
    </description>
</item>

<!-- Item 2 -->
<item>
    <id>46</id>
    <name>Hand Sanitizer</name>
    <img alt="Hand Sanitizer">images/catalogueImg/hand.jpg</img>
    <price>MUR 350</price>
    <type>Beauty</type>
    <description>
        Helps to clean and desinfect perfectly your hands
        wherever you are. This product is enriched in 
        Aloe Vera and honey which perfumes your hand without
        drying them.
    </description>
</item>

<!-- Item 3 -->
<item>
    <id>87</id>
    <name>Aloe Vera Gel</name>
    <img alt="Aloe Vera Gel">images/catalogueImg/aloe.jpg</img>
    <price>MUR 1300</price>
    <type>Health</type>
    <description>
        First product to have received the label of IASC
        (Conseil International Scientifique de l'Aloe Vera), 
        is a product to be used daily to optimise your health.
        Aloe Vera help to maintain the immune system and helps to 
        strenghen the organism efence.
    </description>
</item>

<!-- Item 4 -->
<item>
    <id>74</id>
    <name>Berry Nectar</name>
    <img alt="Berry Nectar">images/catalogueImg/berry.jpg</img>
    <price>MUR 1200</price>
    <type>Health</type>
    <description>

    </description>
</item>

<!-- Item 5 -->
<item>
    <id>18</id>
    <name>Aloe Sunscreen</name>
    <img alt="Aloe Sunscreen">images/catalogueImg/sun.jpg</img>
    <price>MUR 750</price>
    <type>Beauty</type>
    <description>
        This sun care of high protection SPF 30, protects the
        skin from the negative effects of the sun and from
        aging.
    </description>
</item>

    <!-- Item 1 -->
<item>
    <id>45</id>
    <name>Ginkgo Plus</name>
    <img alt="Ginkgo Plus">images/catalogueImg/ginkgo.jpg</img>
    <price>MUR 575</price>
    <type>Health</type>
    <description>
        A mixture of 3 chineese plant including ginkgo biloba and reishi.
        Many traditional medicines identifies that the leaves of the ginkgo biloba 
        have a positive effect on the circulatory system. The reishi is a champion
        used in chineese and japaneese traditional medicines to protect against 
        heart problems.
    </description>
</item>

<!-- Item 2 -->
<item>
    <id>46</id>
    <name>Hand Sanitizer</name>
    <img alt="Hand Sanitizer">images/catalogueImg/hand.jpg</img>
    <price>MUR 350</price>
    <type>Beauty</type>
    <description>
        Helps to clean and desinfect perfectly your hands
        wherever you are. This product is enriched in 
        Aloe Vera and honey which perfumes your hand without
        drying them.
    </description>
</item>

<!-- Item 3 -->
<item>
    <id>87</id>
    <name>Aloe Vera Gel</name>
    <img alt="Aloe Vera Gel">images/catalogueImg/aloe.jpg</img>
    <price>MUR 1300</price>
    <type>Health</type>
    <description>
        First product to have received the label of IASC
        (Conseil International Scientifique de l'Aloe Vera), 
        is a product to be used daily to optimise your health.
        Aloe Vera help to maintain the immune system and helps to 
        strenghen the organism efence.
    </description>
</item>

<!-- Item 4 -->
<item>
    <id>74</id>
    <name>Berry Nectar</name>
    <img alt="Berry Nectar">images/catalogueImg/berry.jpg</img>
    <price>MUR 1200</price>
    <type>Health</type>
    <description>

    </description>
</item>

<!-- Item 5 -->
<item>
    <id>18</id>
    <name>Aloe Sunscreen</name>
    <img alt="Aloe Sunscreen">images/catalogueImg/sun.jpg</img>
    <price>MUR 750</price>
    <type>Beauty</type>
    <description>
        This sun care of high protection SPF 30, protects the
        skin from the negative effects of the sun and from
        aging.
    </description>
</item>

</catalogue>
这是xsl文件


我没有时间提供完整的解决方案,但有一些关于算法的想法:

将匹配/目录/项目的所有元素选择到变量中 在模板中,输出前4项,并将其包装在 让模板递归地调用自己,列表的其余部分不包括前4个
一种方法是最初只选择与每个表行的第一个单元格相对应的item元素,可以这样做

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">


<xsl:template match="/">

<html>
<head>
<link rel="stylesheet" type="text/css" href="catalogueStyle.css"></link>
<link rel="stylesheet" type="text/css" href="style.css"></link>
<title>Catalogue</title>



</head>
<body>  
    <div class="body-wrapper" style="attachment:fixed;">
        <img src="images/header.png"/>
    </div>

    <table border="1">
    <tr>

    <xsl:for-each select="/catalogue/item">

        <td>

        <img src="{img/.}" alt="{img/@alt}" class="imgs-catalogue" title="click for description"/><br/>

        Id: <xsl:value-of select="id/."/><br/>
        Name: <xsl:value-of select="name/."/><br/>
        Type: <xsl:value-of select="type/."/><br/>
        Price: <xsl:value-of select="price/text()"/><br/><br/>
        </td>       

        <xsl:if test="(position() mod 4)=0">
            </tr><tr>
        </xsl:if>

</xsl:for-each>
</tr>
</table>

</body>
</html>

</xsl:template>

</xsl:stylesheet>
<xsl:for-each select="/catalogue/item[position() mod 4 = 1]">
因此,它选择当前项和下面的3个项,每行有4个单元格。对于每一个,您都会输出带有所需详细信息的td

剩下的唯一挑战是最后一行,此时您可能只有不到4个项目来组成这一行。您可以在这里创建一个递归模板来创建空单元格来填充行

试试这个XSLT

<xsl:variable name="cells" select="current()|following-sibling::item[position() &lt; 4]" />
<xsl:for-each select="$cells">

请注意,我已将4参数化,以允许您轻松更改行大小。

这是XSLT问题吗?如果是这样,请编辑您的问题并添加输入XML文档、XSLT样式表和您期望的输出。请在此处寻求帮助:。编辑:请不要链接到信息,将其添加到此处,不要在图像中显示代码,而是以文本形式显示。阅读然后阅读,您的做法是错误的。与其检测何时更改行或尝试插入换行符,不如收集要组成该行的元素,并使用它们进行替换。。。。如果您希望有人对您的示例输入和当前代码发表评论,请发布这些示例输入和代码。@MathiasMüller感谢您的帮助advice@RolfRander让我发布xml文档和xsl文件,以便您更好地理解它
<xsl:stylesheet version="1.0"     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:param name="rowsize" select="4" />

<xsl:template match="/">
<html>
<head>
<link rel="stylesheet" type="text/css" href="catalogueStyle.css"></link>
<link rel="stylesheet" type="text/css" href="style.css"></link>
<title>Catalogue</title>
</head>
<body>  
    <div class="body-wrapper" style="attachment:fixed;">
        <img src="images/header.png"/>
    </div>
    <table border="1">
    <xsl:for-each select="/catalogue/item[position() mod $rowsize = 1]">
    <tr>
        <xsl:variable name="cells" select="current()|following-sibling::item[position() &lt; $rowsize]" />
        <xsl:for-each select="$cells">
        <td>
        <img src="{img/.}" alt="{img/@alt}" class="imgs-catalogue" title="click for description"/><br/>
        Id: <xsl:value-of select="id/."/><br/>
        Name: <xsl:value-of select="name/."/><br/>
        Type: <xsl:value-of select="type/."/><br/>
        Price: <xsl:value-of select="price/text()"/><br/><br/>
        </td>       
        </xsl:for-each>
        <xsl:if test="count($cells) &lt; $rowsize">
            <xsl:call-template name="emptyCells">
                <xsl:with-param name="cells" select="$rowsize - count($cells)" />
            </xsl:call-template>
        </xsl:if>
    </tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>

<xsl:template name="emptyCells">
    <xsl:param name="cells" />
    <xsl:if test="$cells > 0">
        <td></td>
        <xsl:call-template name="emptyCells">
            <xsl:with-param name="cells" select="$cells - 1" />
        </xsl:call-template>
    </xsl:if>
</xsl:template>
</xsl:stylesheet>