【发布时间】:2016-04-07 23:27:08
【问题描述】:
我的 if 语句有问题 浏览器没有解码
<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 文件
<?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>
【问题讨论】:
-
这是一个 XSLT 问题吗?如果是这样,请编辑您的问题并添加输入 XML 文档、您的 XSLT 样式表和您期望的输出。在这里寻求帮助:stackoverflow.com/help/mcve。 编辑:请不要链接到信息(在此处添加)并且不要在图像中显示代码(而是作为文本)。
-
您以错误的方式处理此问题。与其检测何时更改行并尝试插入换行符,不如收集您想要组成行的元素并用
... 包围它们。如果您希望有人对其发表评论,请发布一些示例输入和您当前的代码。 -
@MathiasMüller 感谢您的建议
-
@RolfRander 让我把xml文档和xsl文件贴出来让你更好的理解