2013-08-20 58 views
0

可以使用XSL執行以下操作嗎?將XSL轉換爲div風格

我有以下內容的XML:

<main 
    template.main.style="width: 1000px; height: 400px; margin: 0 auto;"> 
    <child 
     template.item.style="duration: 7200; animation: all;"/> 
</main> 

可以的,例如template.main.styletemplate.item.style有一個div內XSL格式化的值,所以它看起來是這樣?

<div id="main" style="width: 1000px; height: 400px; margin: 0 auto;"> 
    <div class="layer" style="duration: 7200; animation: all;"> 

如果是這樣如何,所有的幫助是非常讚賞..

+0

是的,這是可能的。你嘗試過一些沒有奏效的東西嗎?因此,你想表明你至少對被問到的問題有最少的瞭解。 [你可以查看這個問題的東西,包括在你的問題。](http://meta.stackexchange.com/questions/156810/stack-overflow-question-checklist) –

回答

1

需要更多信息。但這是可能的。例如,你可以這樣做:

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> 
    <xsl:output method="html" encoding="utf-8" indent="yes" /> 
    <xsl:template match="main"> 
     <div> 
     <xsl:attribute name="style"> 
      <xsl:value-of select="@template.main.style" /> 
     </xsl:attribute> 
     </div> 
     <xsl:apply-templates select="child" /> 
    </xsl:template> 
    <xsl:template match="child"> 
     <div> 
     <xsl:attribute name="style"> 
      <xsl:value-of select="@template.item.style" /> 
     </xsl:attribute> 
     </div> 
    </xsl:template> 
</xsl:stylesheet>