【发布时间】:2014-04-15 07:46:23
【问题描述】:
我有一个如下的 XML 文档。
<?xml version="1.0"?>
<document document="wpc_slider_qp">
<properties>
<property prop_name="displayname" prop_ns="http://sapportals.com/xmlns/cm" type="filename"/>
<property type="createdBy">USER.PRIVATE_DATASOURCE.un:LU23921</property>
</properties>
<elements>
<element type="sliderimage" alt="Slider 1 Tooltip" width="700" height="306">="/irj/go/km/docs/wpccontent/Sites/Administration/Site Content/image-slider-1.jpg</element>
<element title="" type="sliderlink" linkid="2ece8f2a15920a838038554563a046b2" targetnew="false" rid="http://www.google.com"/>
<element type="sliderimage" alt="Slider 2 Tooltip" width="700" height="306">="/irj/go/km/docs/wpccontent/Sites/Administration/Site Content/image-slider-2.jpg</element>
<element title="" type="sliderlink" linkid="75af9a52cab35aa864d80f4563a0db8f" targetnew="false" rid="http://www.yahoo.com"/>
</elements>
<relatedlinks/>
<relatedfiles/>
</document>
我想使用 XSL 将其转换为链接此的东西..
<div id="sliderFrame">
<div id="slider">
<a href="http://www.google.com"><img border="0" src="/irj/go/km/docs/wpccontent/Sites/Administration/Site Content/image-slider-1.jpg" height="306" width="700"/></a>
<a href="http://www.yahoo.com"><img border="0" src="/irj/go/km/docs/wpccontent/Sites/Administration/Site Content/image-slider-2.jpg" height="306" width="700"/></a>
</div>
</div>
到目前为止,这是我的 XSL...
<?xml version="1.0"?>
<!DOCTYPE stylesheet [
<!ENTITY apos "'" ><!-- replace ' with html escape character for ' -->
]>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:wpc="com.sap.nw.wpc.km.service.editor.xslt.XsltHelperCore">
<xsl:template match="/">
<xsl:output method="html"/>
<html>
<head>
<link href="js-image-slider.css" rel="stylesheet" type="text/css" />
<script src="js-image-slider.js" type="text/javascript">function empty() return;</script>
</head>
<div id='sliderFrame'>
<div id='slider'>
<xsl:for-each select="document/elements/element">
<xsl:if test="@type='sliderimage'">
<img border="0">
<xsl:attribute name="src"><xsl:value-of disable-output-escaping="yes" select="wpc:getWebDavAccess(string(current()))"/></xsl:attribute>
<xsl:if test="string-length(@height)!=0">
<xsl:attribute name="height"><xsl:value-of disable-output-escaping="yes" select="@height"/></xsl:attribute>
</xsl:if>
<xsl:if test="string-length(@width)!=0">
<xsl:attribute name="width"><xsl:value-of disable-output-escaping="yes" select="@width"/></xsl:attribute>
</xsl:if>
<xsl:if test="string-length(document/elements/element[@type='sliderimage']/@alt)!=0">
<xsl:attribute name="alt"><xsl:value-of disable-output-escaping="yes" select="document/elements/element[@type='sliderimage']/@alt"/></xsl:attribute>
</xsl:if>
</img>
</xsl:if>
</xsl:for-each>
</div>
</div>
<br />
<br />
<xsl:for-each select="document/elements/element">
<xsl:if test="@type='sliderlink'">
<a>
<xsl:attribute name="href">
<xsl:value-of disable-output-escaping="yes" select="wpc:getHrefValue(string(current()/@rid), string(/document/@locale))"/>
</xsl:attribute>
<xsl:attribute name="onclick">
<xsl:value-of disable-output-escaping="yes" select="wpc:getOnClickValue(string(current()/@rid), string(/document/@locale),string(document/elements/element[@type='sliderlink']/@targetnew))"/>
</xsl:attribute>
<xsl:attribute name="target">
<xsl:value-of disable-output-escaping="yes" select="wpc:getTarget(string(current()/@targetnew))"/>
</xsl:attribute>
test
</a>
</xsl:if>
</xsl:for-each>
</html>
</xsl:template>
</xsl:stylesheet>
我能够得到一张低于另一张的图像,但我无法弄清楚如何在图像周围添加 A 标签。任何帮助将不胜感激。
【问题讨论】:
-
你为什么在所有东西上都使用
disable-output-escaping?