使用XSL转换XML和HTML - 输出为空

时间:2015-10-23 19:32:56

标签: html xml xslt

我是XML和XSL的新手,可以转换为HTML。我创建了我的XML和XSL,但我的输出是空白的。我认为这与节点不匹配有关?但我不确定。任何帮助将不胜感激!

这是我的XSL代码:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:wci="http://www.jda.com/taglibs/wci" xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:fmt="http://java.sun.com/jsp/jstl/fmt">
<xsl:template match="Privacy">      
<xsl:variable name="uppercase">ABCDEFGHIJKLMNOPQRSTUVWXYZ</xsl:variable>
<xsl:variable name="lowercase">abcdefghijklmnopqrstuvwxyz</xsl:variable>
<xsl:choose>
<xsl:when test="//ContentSettings/LenovoCodeBase">
<c:if><xsl:attribute name="test">
<xsl:text disable-output-escaping="yes">${empty LenovoCodeBase}</xsl:text>
</xsl:attribute>
<c:set var="LenovoCodeBase" scope="request">
<xsl:attribute name="value">
<xsl:value-of select="//ContentSettings/LenovoCodeBase"/>
</xsl:attribute>
</c:set>
</c:if>
</xsl:when>
<xsl:otherwise>
<c:if>
<xsl:attribute name="test">
<xsl:text disable-output-escaping="yes">${empty LenovoCodeBase}</xsl:text>
</xsl:attribute>
<c:set var="LenovoCodeBase" scope="request" value="OWv2"/>
</c:if>
</xsl:otherwise>
</xsl:choose>
<div role="main" class="mainContent pageWrapper contentContainer">
<div id="privacyWrap">
<!-- beginning of left navigation bar area -->  
<xsl:for-each select="Tab">
<div class="nav-item-header">
<ul>
<li>

</li>
</ul>
</div>
</xsl:for-each>
<!-- end of left navigation bar area -->
<!-- beginning of content area with anchors -->
<div class="privacyContent"> 
  <xsl:for-each select="ContentText">
  <h1><xsl:value-of select="PageTitle" disable-output-escaping="yes"/><xsl:attribute name="a-name"><xsl:value-of select="PageTitle"/></xsl:attribute><xsl:value-of select="PageTitle"/></h1>
  <xsl:value-of select="Content" disable-output-escaping="yes"/>
  </xsl:for-each>
  </div>
<!--End of content area with anchors -->
<!-- beginning of right column bar area -->
<div class="privacyRightColumn">
  <xsl:for-each select="ContentText">
  <xsl:value-of select="Content" disable-output-escaping="yes"/>
</xsl:for-each>
</div>
<!-- End of right column bar area -->
</div>
</div>
</xsl:template>
</xsl:stylesheet>

这是我的XML:

<container name="Privacy" location="Privacy">
<tab name="Navigation">
    <label>Navigation</label>
    <container name="ContentText" location="ContentText" default="1" min="0" max="1">
            <item name="LinkLabel" pathid="LinkLabel">
                <label>Link Label</label>
                <text required="t" maxlength="" />
            </item>
            <item name="URLPath" pathid="URLPath">
                <label>URL Path</label>
                <text required="t" />
            </item>
        </container>        
    </tab>
<tab name="Content">
<label>Content</label>
    <container name="Tab" location="Tab" min="0" max="40" default="1">
    <label>Content Title</label>
        <container name="PageTitle" location="PageTitle" default="0" min="1" max="1">
            <item name="PageTitle" pathid="PageTitle">
                <label>Page Title</label>
                <text required="f" maxlength=""/>
            </item>
        <label>Content</label>
        <container name="Content" location="Content" default="1" min="0" max="40">
            <item name="Content" pathid="Content">
                <label>Content</label>
                <textarea external-editor-config="rich-text-area" external-editor="tinymce" rows="4" cols="100"/>
            </item>
        </container>
        </container>    
    </container>        
    </tab>
<tab name="SidebarContent">
    <container name="Sidebar" location="Sidebar">
        <label>Right Sidebar Area</label>
        <container name="sidebarcontent" location="sidebarcontent" min="0" max="4" default="1">
            <label>Content</label>
            <item name="Content" pathid="Content">
                <label>Content</label>
                <description>Content Text</description>
                <textarea external-editor-config="rich-text-area" external-editor="tinymce" rows="4" cols="50"/>
            </item>
        </container>
    </container>        
</tab>  

1 个答案:

答案 0 :(得分:0)

  

我认为它与未匹配的节点有关?

嗯,从一开始就开始:

<xsl:template match="Privacy">  

在输入中不匹配任何内容,因为没有名为Privacy的元素。我怀疑你打算引用container[@name="Privacy"]

同样,稍后您会引用ContentText - 但这也是container元素的属性。