简体   繁体   English

XSLT输出不显示

[英]XSLT output does not display

I am a novice to XSLT. 我是XSLT的新手。 I am trying to generate a text file from an XSLT. 我正在尝试从XSLT生成文本文件。 When I run XSLT against the input XML using XALAN parser, the text file generates without an output. 当我使用XALAN解析器对输入XML运行XSLT时,将生成文本文件而没有输出。

This is the XSLT 这是XSLT

<xsl:stylesheet version="2.0"
            xmlns:xs="http://www.w3.org/2001/XMLSchema"
            xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:output method="text" />

<xsl:template match="/">
    <xsl:variable name="cities" as="xs:string*">
         <xsl:sequence select="addressbook/address/city" />
         <xsl:sequence select="'Virginia'" />
    </xsl:variable>
    <xsl:text>These are some of the cities:&#xA;&#xA;</xsl:text>
    <xsl:value-of select="$cities" separator="&#xA;" />
</xsl:template>

This is the XML 这是XML

<?xml version="1.0" ?>
<addressbook>
 <address>
    <name>Peter Thompson</name>
    <stree>3456 South Blvd.</stree>
    <city>Chicago</city>
    <state>IL</state>
    <zip-code>34678</zip-code>
 </address>

 <address>
    <name>Jason Thompson</name>
    <stree>3456 Fort Main</stree>
    <city>South Carolina</city>
    <state>NC</state>
    <zip-code>67878</zip-code>
 </address>

I try to compile it in this way: 我尝试以这种方式进行编译:

java -classpath ~/Downloads/xalan/xalan.jar org.apache.xalan.xslt.Process -in cities.xml -xsl cities.xsl -out citiesop.txt

The cities.txt file is generated with just the output: 仅使用输出生成cities.txt文件:

These are some of the cities. 这些是一些城市。

Please assist me to understand what is wrong here. 请协助我了解这里的问题。

Xalan only supports XSLT 1.0. Xalan仅支持XSLT 1.0。 Due to version="2.0" it uses relaxed rules for syntax checking and simply ignores the <xsl:sequence> elements. 由于version="2.0"它使用宽松的规则进行语法检查,并且仅忽略<xsl:sequence>元素。 Therefore your variable cities is empty. 因此,您的可变cities为空。

For this stylesheet you need to use a XSLT 2.0 engine, like Saxon. 对于此样式表,您需要使用XSLT 2.0引擎,例如Saxon。

Just rewrite it in XSLT 1.0: 只需在XSLT 1.0中重写它即可:

<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:output method="text" />

<xsl:template match="/">
    <xsl:text>These are some of the cities:&#xA;&#xA;</xsl:text>
    <xsl:for-each select="addressbook/address/city" >
        <xsl:value-of select="."/>
        <xsl:text>&#xA;</xsl:text>
    </xsl:for-each>
    <xsl:text>Virginia</xsl:text>
</xsl:template>

</xsl:stylesheet>

PS South Carolina and Virginia are states , not cities . PS南卡罗来纳州和弗吉尼亚州是 ,而不是城市

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM