【问题标题】:XML - XSL not workingXML - XSL 不工作
【发布时间】:2016-12-03 08:04:57
【问题描述】:

我在 XSL 中提到的样式不适用于 XML。这是我得到的输出output on mozilla firefox

这是 XSL 代码

    <?xml version = "1.0"?> 
    <xsl:stylesheet version = "1.0" xmlns:xsl ="http://www.w3.org/1999/XSL/Transform" 
    xmlns = "http://www.w3.org/TR/xhtml1/strict"> 
    <xsl:template match = "/"> 
    <h2> Student information </h2> 
    <xsl:for-each select="student">
    USN:<span style = "font-style: italic;color:red">
    <xsl:value-of select = "USN" /><br /></span> 
    Name:<span style = "font-style: italic"> 
    <xsl:value-of select = "name" /><br /></span> 
    college Name:<span style = "font-style: italic;color:green"> 
    <xsl:value-of select = "college" /><br /></span>
    Branch:<span style = "font-style: italic;color:blue"> 
    <xsl:value-of select = "branch" /><br /></span> 
    Year of Joining:<span style = "font-style: italic;color:yellow"> 
    <xsl:value-of select = "YOJ" /><br /></span> 
    Email-id:<span style = "font-style: italic;color:blue"> 
    <xsl:value-of select = "email" /><br /></span> 
    </xsl:for-each> 
    </xsl:template> 
    </xsl:stylesheet>  

这里是 XML 代码

<?xml version="1.0"?> 
<?xml-stylesheet type="text/xsl" href="info.xsl"?> 
<student> 
<USN> 4PM10CS020 </USN> 
<name> John Doe </name>
<college> PESITM, Shivamogga. </college>
<branch> CSE </branch> 
<YOJ> 2010 </YOJ> 
<email> John@me.com </email> 
</student>  

我做错了什么?

【问题讨论】:

  • 请尝试关注。我希望它对你有用

标签: xml html xslt


【解决方案1】:

这完全取决于您在转换过程中选择的输出方法。 在下文中,我将输出方法定义为xml,它将为您提供 XML 格式的输出,然后您可以进行渲染。或者尝试将输出方法设置为html

找到以下工作的 XSL。

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns1="http://locomotive/bypass/docx" >
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>

<!-- identity transform -->
<xsl:template match="node()">
    <xsl:copy>
        <xsl:apply-templates select="node()"/>
    </xsl:copy>
</xsl:template>

   <xsl:template match="/">
        <h2> Student information </h2>
        <xsl:for-each select="student">
            USN:
            <span style="font-style: italic;color:red">
                <xsl:value-of select="USN" />
                <br />
            </span>
            Name:
            <span style="font-style: italic">
                <xsl:value-of select="name" />
                <br />
            </span>
            college Name:
            <span style="font-style: italic;color:green">
                <xsl:value-of select="college" />
                <br />
            </span>
            Branch:
            <span style="font-style: italic;color:blue">
                <xsl:value-of select="branch" />
                <br />
            </span>
            Year of Joining:
            <span style="font-style: italic;color:yellow">
                <xsl:value-of select="YOJ" />
                <br />
            </span>
            Email-id:
            <span style="font-style: italic;color:blue">
                <xsl:value-of select="email" />
                <br />
            </span>
        </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>

为您提供 Workgin 演示:http://xsltransform.net/ejivdHb/25

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多