对于liferay中,journal的structure的元素有多种类型,boolean,list,text,image等。text和image类型的对应xsl输出的写法在网上都能搜索到。这是我在javaeye中提问关于boolean等其他类型的xsl输出怎么写,版主给了我详细的解答:
你的问题牵涉到两方面,一个是怎么编写template,在liferay高版本中,提供vm格式的template,这个要比xsl容易多了,可以查看liferay自带的例子。
比如
- <div class="journal-adv-article-2b-container">
- <h2>$header.getData()</h2>
- <div class="hr"><hr /></div>
- <div class="content-container">
- <img class="article-image" src="$image.getData()" />
- <h2>$subheader.getData()</h2>
- <p>
- $content.getData()
- #if ($more-url.getData() != "")
- <a href="$more-url.getData()">more <img src="@root_path@/image/image_gallery?img_id=11411" /></a>
- #end
- </p>
- <div class="footer">
- #if ($footer.getData() != "")
- $footer.getData()
- #end
- </div>
- </div>
- </div>
<script type="text/javascript">render_code();</script> 其中$开头的变量就是你在struct中定义的每个element 的名称.
上面的代码估计你都能猜出大体的样子了.
另一个是xls,这个不是一个回信就能完全解释清楚的,我只能告诉你一些大概的概念.
xls是一种转换规则,把一份xml转换成另外的的一份xml,你看xls文件的时候会看到一些 tag 是 xls:开头的,这些是xls定义规则,其他的则是照样输出.
拿你的例子说明
- <img>
- <xsl:attribute name=" src ">
- <xsl:value-of disable-output-escaping=" yes "select=" root/dynamic-elem
- ent[@name='image-1']/dynamic-content " />
- </xsl:attribute>
- </img>
第一个 img不是xsl tag,直接输出,这样就会输出一个
<img>标签
<xsl:attribute name=" src "> 是一个xsl规则
说明在前面输出的tag上添加一个 attribute "src"
这样输出的内容就成为
<img src=>,src的值由更内层嵌套提供,在这里是<xsl:value-of disable-output-escaping=" yes "select=" root/dynamic-elem
ent[@name='image-1']/dynamic-content " />
<xsl:value-of> 的意思是根据某种条件查找原始xml的某个节点,然后输出这个节点的value (节点可以是tag,也可以是某个tag的attribute)
在这里就是查找一个节点,这个节点的层次关系是
root/dynamic-element/dynamic-content而且其中的dynamic-element 的有一个attribute叫name值是image-1
假设我们在编辑article时填写 abc.png,那么这个xls的输出,最后就成为
<img src="abc"/>
xsl里还带有一些逻辑性的tag,比如 <xsl:for-each> <xsl:if>可以完成更复杂的转换规则.
我写了个boolean类型元素的输出:
<input type="checkbox">
<xsl:attribute name="checked">
<xsl:variable name="booleanValue">
<xsl:value-of disable-output-escaping="yes" select="rootdynamic-element[@name='boolean']dynamic-content"/>
</ xsl:variable>
<xsl:if test="$booleanValue == 'true'">
<xsl:text>checked</ xsl:text>
</ xsl:if>
<xsl:attribute>
</input>
以下是版主对我写的进行了修改:
基本思路正确,不过html中checkbox比较愚蠢
<input type=checkbox checked/> 打钩
<input type=chechbox/> 不打钩
所以你要把if 放在<xsl:attribute name="checked">外面
<input type="checkbox">
<xsl:variable name="booleanValue">
<xsl:value-of disable-output-escaping="yes" select="rootdynamic-element[@name='boolean']dynamic-content"/>
</ xsl:variable>
<xsl:if test="$booleanValue == 'true'">
<xsl:attribute name="checked">true</xsl:attribute>
</ xsl:if>
</input>
在你的代码上改的,看懂意思就可以,我也不知道是不是能跑的通.
另,除非是有固定格式需求的article,如果普通用户,还是用自带的fckeditor比较好,这玩样可以从word贴过来.