为何在fo:block中使用xsl:value-of时IntelliJ IDEA报错?
XSL 2.0文件在IntelliJ IDEA中打开时报错的解决方法
我编写了如下XSL 2.0文件:
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format"> <xsl:output media-type="text" omit-xml-declaration="yes"/> <xsl:template match="root/branch"> <fo:root> <fo:layout-master-set> <fo:simple-page-master master-name="simple" page-height="29.7cm" page-width="21cm" margin-top="1cm" margin-bottom="2cm" margin-left="2.5cm" margin-right="2.5cm"> <fo:region-body margin-top="3cm"/> <fo:region-before extent="3cm"/> <fo:region-after extent="1.5cm"/> </fo:simple-page-master> </fo:layout-master-set> <fo:page-sequence master-reference="simple"> <fo:flow flow-name="xsl-region-body"> <fo:block font-size="12pt" font-family="sans-serif" line-height="15pt" space-after.optimum="3pt" text-align="justify"> <xsl:value-of select="branch/greenLeave"/> <xsl:value-of select="branch/yellowLeave"/> </fo:block> </fo:flow> </fo:page-sequence> </fo:root> </xsl:template> </xsl:stylesheet>
用IntelliJ IDEA打开该文件时出现报错,错误信息为:元素类型 "fo:root" 必须后跟属性说明、">" 或 "/>"。
问题原因及解决方案
输出类型不匹配
你设置了<xsl:output media-type="text" ...>,但模板中输出的是XSL-FO格式的XML内容。IDE的校验逻辑会因为输出类型为纯文本,对模板内的XML标签语法产生误判。
解决方法:将<xsl:output>的media-type改为XML类型,比如:<xsl:output media-type="application/xml" omit-xml-declaration="yes"/>XPath选择器逻辑错误(附加优化)
模板匹配的是root/branch,当前上下文已经是branch节点,select="branch/greenLeave"会查找当前节点下的子branch节点,这大概率不符合需求。应改为直接选择子节点:<xsl:value-of select="greenLeave"/> <xsl:value-of select="yellowLeave"/>
内容的提问来源于stack exchange,提问作者Florian
相关产品推荐
相关产品推荐

