在浏览器中预览XML时,我只希望使用XSL看到某些项
When previewing XML in browser, I only want to see certain items using XSL
我希望XSL只将每个PRODUCT/PRODUCT_IMAGES节点中的第一个ITEM节点中的第一个PRODUCT_IMAGE_FILE节点输出到您可以在记事本中找到的简单列表中。我一直在试着让它工作,但是很难。
这是我需要看到的,最终结果:
hello/this_d_one1.jpg
hello/this_d_one33.jpg
XML: <?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="test.xsl" type="text/xsl"?>
<products>
<product>
<Person>Jim</Person>
<Product_Images>
<item>
<Product_Image_File>hello/this_d_one1.jpg</Product_Image_File>
</item>
<item>
<Product_Image_File>hello/testNOTHISONE.jpg</Product_Image_File>
</item>
</Product_Images>
</product>
<product>
<Person>Nancy</Person>
<Product_Images>
<item>
<Product_Image_File>hello/this_d_one33.jpg</Product_Image_File>
</item>
<item>
<Product_Image_File>hello/testNOTHISONE3.jpg</Product_Image_File>
</item>
</Product_Images>
</product>
</products>
这是我的测试。XSL:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:template match="products">
<xsl:call-template name="header" />
<xsl:apply-templates select="product" />
</xsl:template>
<xsl:template name="header">
<xsl:for-each select="//product[1]/product_images/item/child::*" >
<xsl:value-of select="name()" />
<xsl:if test="following-sibling::*">|</xsl:if>
</xsl:for-each>
<xsl:text>
</xsl:text>
</xsl:template>
<xsl:template match="product/product_images/item">
<xsl:for-each select="child::*" >
<xsl:value-of select="." />
<xsl:if test="following-sibling::*">|</xsl:if>
</xsl:for-each>
<xsl:text>
</xsl:text>
</xsl:template>
</xsl:stylesheet>
如果你只是在浏览器中显示,你可以这样做:
XML输入(固定为格式良好)
<products>
<product>
<Person>Jim</Person>
<Product_Images>
<item>
<Product_Image_File>hello/this_d_one1.jpg</Product_Image_File>
</item>
<item>
<Product_Image_File>hello/testNOTHISONE.jpg</Product_Image_File>
</item>
</Product_Images>
</product>
<product>
<Person>Nancy</Person>
<Product_Images>
<item>
<Product_Image_File>hello/this_d_one33.jpg</Product_Image_File>
</item>
<item>
<Product_Image_File>hello/testNOTHISONE3.jpg</Product_Image_File>
</item>
</Product_Images>
</product>
</products>
XSLT 1.0 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/*">
<xsl:apply-templates select="product/Product_Images[1]/item[1]/Product_Image_File[1]"/>
</xsl:template>
<xsl:template match="Product_Image_File">
<xsl:value-of select="."/>
<br/>
</xsl:template>
</xsl:stylesheet>
(生)
hello/this_d_one1.jpg<br>hello/this_d_one33.jpg<br>
(呈现)
hello/this_d_one1.jpg
hello/this_d_one33.jpg
相关文章:
- Amd,希望确保某个东西总是最后执行
- 我想使用模态通过php文件发送邮件,并且我希望在提交关闭后关闭pop
- 我希望只有在我滚动页面后才能显示我的返回页首图标
- 我希望在不替换现有变量的情况下恢复localStorage中的变量
- 希望日期开始结束于while循环中的一个房间id的一个数组
- 页面在我的javascript执行后重新加载,我不希望它这样做
- 自定义调查页面并希望在时区内按时间忽略(可能)
- 在javascript中使用split函数希望在页面加载时拆分url
- Jquery幻灯片以一行左侧的图像开始,但我希望它从右端开始
- PHP REST服务抛出异常——希望避免控制台错误
- 我希望这个日期选择器可以从1990年到2000年之间的年份中选择日期
- 我有多个复选框,并希望为其中 2 个制定规则,以便如果我选择 1 个,则无法选择另一个
- VS2010 javascript调试器希望在VS2010的新实例中启动
- 如何隐藏滚动条,但希望它继续工作
- Noob web开发人员希望添加web设计和交互
- 正在创建网页,并希望将外部链接调用为html和css
- 如何在 ajax 调用上阻止(我希望它阻止)
- 在xsl中为body onload添加一个值
- 希望在文本中插入选定的值
- 在浏览器中预览XML时,我只希望使用XSL看到某些项