关于journal的structure的元素输出

对于liferay中,journal的structure的元素有多种类型,boolean,list,text,image等。text和image类型的对应xsl输出的写法在网上都能搜索到。这是我在javaeye中提问关于boolean等其他类型的xsl输出怎么写,版主给了我详细的解答:

你的问题牵涉到两方面,一个是怎么编写template,在liferay高版本中,提供vm格式的template,这个要比xsl容易多了,可以查看liferay自带的例子。
比如

代码
  1. <div class="journal-adv-article-2b-container">  
  2.     <h2>$header.getData()</h2>  
  3.   
  4.     <div class="hr"><hr /></div>  
  5.   
  6.     <div class="content-container">  
  7.         <img class="article-image" src="$image.getData()" />  
  8.   
  9.         <h2>$subheader.getData()</h2>  
  10.   
  11.         <p>  
  12.             $content.getData()   
  13.   
  14.             #if ($more-url.getData() != "")   
  15.                     <a href="$more-url.getData()">more <img src="@root_path@/image/image_gallery?img_id=11411" /></a>  
  16.             #end   
  17.         </p>  
  18.   
  19.         <div class="footer">  
  20.             #if ($footer.getData() != "")   
  21.                 $footer.getData()   
  22.             #end   
  23.         </div>  
  24.     </div>  
  25. </div>  

<script type="text/javascript">render_code();</script> 其中$开头的变量就是你在struct中定义的每个element 的名称.
上面的代码估计你都能猜出大体的样子了.

另一个是xls,这个不是一个回信就能完全解释清楚的,我只能告诉你一些大概的概念.
xls是一种转换规则,把一份xml转换成另外的的一份xml,你看xls文件的时候会看到一些 tag 是 xls:开头的,这些是xls定义规则,其他的则是照样输出.

拿你的例子说明

代码
  1. <img>    
  2. <xsl:attribute name=" src ">    
  3. <xsl:value-of disable-output-escaping=" yes "select=" root/dynamic-elem    
  4. ent[@name='image-1']/dynamic-content " />    
  5. </xsl:attribute>    
  6. </img>  
<script type="text/javascript">render_code();</script>

第一个 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贴过来.

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值