我的 xsl 转换出现错误:在添加文本、注释、pi 或子元素节点后,无法将属性和命名空间节点添加到父元素。
这是我的xsl。有任何想法吗?我进行了研究,可能是我正在插入一个子元素或复制和插入子元素,然后尝试向父元素添加一个属性,但我看不到我在哪里这样做。请帮忙。
<xsl:template match="legislation:lncontent" mode="lmt">
<xsl:variable name="act">Act <xsl:value-of select="concat(//ln:actPrincipal/@number,' of ',//ln:actPrincipal/@year)"/></xsl:variable>
<!--note to check for ammendment also -->
<lmt:xmlfile title="The Act">
<lmt:mark name="{concat('XML_',$act)}" />
<xsl:apply-templates select="@*|node()">
<xsl:with-param name="act" select="$act"/>
</xsl:apply-templates>
</lmt:xmlfile>
</xsl:template>
<xsl:template match="@*|node()" name="identity">
<xsl:param name="act" />
<xsl:copy>
<xsl:apply-templates select="@*|node()">
<xsl:with-param name="act" select="$act"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
<xsl:template match="legislation:docBody">
<xsl:param name="act" />
<xsl:apply-templates select="@*|node()">
<xsl:with-param name="act" select="$act"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="legislation:lncontent">
<xsl:param name="act" />
<xsl:apply-templates select="*|node()">
<xsl:with-param name="act" select="$act"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="legislation:section[@label]">
<xsl:param name="act" />
<xsl:param name="vAttribs" />
<xsl:variable name="title">
<xsl:choose>
<xsl:when test="string-length(legislation:title)>0">
<xsl:value-of select="concat(./@label,'. ',legislation:title)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat(./@label,'. ',legislation:body)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<lmt:xmlfile title="{substring($title,1,string-length($title)-1)}">
<lmt:mark>
<xsl:attribute name="name">
<xsl:apply-templates select="." mode="mark">
<xsl:with-param name="act" select="$act"/>
</xsl:apply-templates>
</xsl:attribute>
</lmt:mark>
<lncontent>
<xsl:copy-of select="//lncontent/namespace::*"/>
<xsl:copy-of select="//lncontent/@*"/>
<docBody>
<xsl:call-template name="identity" >
<xsl:with-param name="act" select="$act"/>
</xsl:call-template>
</docBody>
</lncontent>
</lmt:xmlfile>
</xsl:template>
<xsl:template match="legislation:schedule[@label]">
<xsl:param name="act" />
<xsl:param name="vAttribs" />
<xsl:variable name="title">
<xsl:choose>
<xsl:when test="legislation:title/subTitle">
<xsl:variable name="subtitle">
<xsl:value-of select="legislation:title/subTitle"/>
</xsl:variable>
<xsl:variable name="stitle">
<xsl:value-of select="substring(title,0,string-length($subtitle)-2)"/>
</xsl:variable>
<xsl:value-of select="concat($stitle,' ',$subtitle)"/>
</xsl:when>
<xsl:otherwise>
<!--!<xsl:value-of select="concat(title,' ',//db:body)"/> -->
<xsl:value-of select="legislation:title"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<lmt:xmlfile title="{$title}">
<lmt:mark>
<xsl:attribute name="name">
<xsl:apply-templates select="." mode="mark">
<xsl:with-param name="act" select="$act"/>
</xsl:apply-templates>
</xsl:attribute>
</lmt:mark>
<lncontent>
<xsl:copy-of select="//lncontent/namespace::*"/>
<xsl:copy-of select="//lncontent/@*"/>
<docBody>
<xsl:call-template name="identity" >
<xsl:with-param name="act" select="$act"/>
</xsl:call-template>
</docBody>
</lncontent>
</lmt:xmlfile>
</xsl:template>
<xsl:template match="legislation:subSection[@label] | legislation:para[@label] | legislation:subPara[@label] | legislation:item[@label]">
<xsl:param name="act" />
<xsl:if test="string-length(@label)>0">
<lmt:mark>
<xsl:attribute name="name">
<xsl:apply-templates select="." mode="mark">
<xsl:with-param name="act" select="$act"/>
</xsl:apply-templates>
</xsl:attribute>
</lmt:mark>
</xsl:if>
<xsl:call-template name="identity" >
<xsl:with-param name="act" select="$act"/>
</xsl:call-template>
</xsl:template>
<xsl:template match="legislation:term">
<xsl:param name="act" />
<lmt:mark>
<xsl:attribute name="name">
<xsl:apply-templates select="." mode="mark">
<xsl:with-param name="act" select="$act"/>
</xsl:apply-templates>
</xsl:attribute>
</lmt:mark>
<xsl:call-template name="identity" >
<xsl:with-param name="act" select="$act"/>
</xsl:call-template>
</xsl:template>
<xsl:template match="legislation:term" mode="mark">
<xsl:param name="act" />
<xsl:apply-templates select="term" mode="mark" />
<xsl:variable name="term">
<xsl:value-of select="."/>
</xsl:variable>
<xsl:value-of select="concat('XML_',$act,' def: ',$term)" />
</xsl:template>
<xsl:template match="legislation:section" mode="mark">
<xsl:param name="act" />
<xsl:if test="ancestor::*[@label]">
<xsl:apply-templates select="ancestor::*[@label][1]" mode="mark" >
<xsl:with-param name="act" select="$act"/>
</xsl:apply-templates>
<xsl:text> </xsl:text>
</xsl:if>
<xsl:value-of select="concat('XML_',$act,' s ',@label)" />
</xsl:template>
<xsl:template match="legislation:schedule" mode="mark">
<xsl:param name="act" />
<xsl:if test="ancestor::*[@label]">
<xsl:apply-templates select="ancestor::*[@label][1]" mode="mark" />
<xsl:text> </xsl:text>
</xsl:if>
<xsl:value-of select="concat('XML_',$act,' sch ',@label)" />
</xsl:template>
<xsl:template match="legislation:*" mode="mark">
<xsl:param name="act" />
<xsl:apply-templates select="ancestor::*[@label][1]" mode="mark" >
<xsl:with-param name="act" select="$act"/>
</xsl:apply-templates>
<xsl:if test="string-length(@label) > '0'">
<xsl:value-of select="concat('(',@label, ')')" />
</xsl:if>
</xsl:template>
调用“legislation:lncontent”匹配的模板
<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:db="/schema/docBook"
xmlns:ln ="/schema/LnNamespace"
xmlns:lmt="/schema/lmt"
xmlns:lawreport=/schema/lawreport"
xmlns:legislation="/schema/legislation"
xmlns:programme="/schema/programme"
xmlns:law24Publication = /schema/clientDevelopment/law24"
xmlns:law24Article = "/schema/clientDevelopment/law24/article"
xmlns:pgsLandingPage = "/schema/PSL"
xmlns:pgsContent = "/schema/PGS">
<xsl:output version="1.0" encoding="ISO-8859-1" method="xml" indent="yes" media-type="text/xml" omit-xml-declaration="no"/>
<xsl:namespace-alias stylesheet-prefix="db" result-prefix="xml"/>
<xsl:namespace-alias stylesheet-prefix="ln" result-prefix="xml"/>
<xsl:namespace-alias stylesheet-prefix="lawreport" result-prefix="xml"/>
<xsl:namespace-alias stylesheet-prefix="legislation" result-prefix="xml"/>
<xsl:namespace-alias stylesheet-prefix="programme" result-prefix="xml"/>
<xsl:namespace-alias stylesheet-prefix="law24Article" result-prefix="xml"/>
<xsl:namespace-alias stylesheet-prefix="law24Publication" result-prefix="xml"/>
<xsl:namespace-alias stylesheet-prefix="pgsLandingPage" result-prefix="xml"/>
<xsl:namespace-alias stylesheet-prefix="pgsContent" result-prefix="xml"/>
<xsl:variable name="xslpath"></xsl:variable>
<xsl:template match="/">
<lmt:document>
<xsl:variable name="xsl">
<xsl:choose>
<xsl:when test="legislation:*">BWAXlegislationpublication.xsl</xsl:when>
<xsl:when test="lawreport:*">BWAXlawreportpublication.xsl</xsl:when>
<xsl:when test="programme:*">BWAXprogrammepublication.xsl</xsl:when>
<xsl:when test="law24Publication:*">BWAXlaw24Publication.xsl</xsl:when>
<xsl:when test="law24Article:*">BWAXlaw24Article.xsl</xsl:when>
<xsl:when test="pgsLandingPage:*">BWAXPGSPage.xsl</xsl:when>
<xsl:when test="pgsContent:*">BWAXPGSContent.xsl</xsl:when>
</xsl:choose>
</xsl:variable>
<xsl:if test="$xsl!=''">
<xsl:attribute name="xsl">
<xsl:value-of select="concat($xslpath,$xsl)"/>
</xsl:attribute>
</xsl:if>
<xsl:variable name="indexsheet">
<xsl:choose>
<xsl:when test="lawreport:*">XML.xil</xsl:when>
</xsl:choose>
</xsl:variable>
<xsl:if test="$indexsheet!=''">
<xsl:attribute name="indexsheet">
<xsl:value-of select="$indexsheet"/>
</xsl:attribute>
</xsl:if>
<xsl:apply-templates mode="lmt"/>
</lmt:document>
<!--<xsl:apply-templates mode="lmt"/>-->
</xsl:template>
示例 XML:
<lncontent xmlns="/schema/legislation" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="/schema/legislation LNLegislation.xsd" xmlns:atieqn="http://www.arbortext.com/namespace/atieqn" xmlns:lng="/schema/Generic" xmlns:ln="/schema/LnNamespace" xmlns:md="/schema/metaData">
<docInfo filename="" lastupdated="" processdate="">
<lmt xmlns="/schema/metaData">
<title title="" />
<titlePath>
<title1 groupid="" id=""></title1>
<title2 groupid="" id=""></title2>
<title3 groupid="" id=""></title3>
<title4 groupid="" id=""></title4>
<title5 groupid="" id=""></title5>
<title6 groupid="" id=""></title6>
</titlePath>
<currentness>
<currentness-author></currentness-author>
</currentness>
</lmt>
<version creationDate="" lastVersionDate="" versionDate="" versionID="" xmlns="/schema/metaData" />
<search xmlns="/schema/metaData">
<language language="En" />
<referenceFrom fromDoc="from" toDoc="to" what="what" when="when" where="where" why="why" />
<referenceTo fromDoc="from" toDoc="to" what="what" when="when" where="where" why="why" />
<related docUrl="www.docurl.com" what="what" where="where" />
<subject subject="act" />
<documentType></documentType>
<yearPublished>1996</yearPublished>
<region></region>
<publicationSource></publicationSource>
</search>
</docInfo>
</lncontent>