以前一个类似的问题是:"追踪 - 源 - 元素 - 通过 - 多 - xsl - 变换",但我正在寻找方式跟踪失败/成功编译等的xsl / xml文件行号。我有多个通行证限制模板"模式"。与此同时,我可以在问题根源寻求帮助:
在多传递XSL中,Pass1使用文件' XSLT1'转换MSWord(2003)标签。其中包括文件' XSLT2'它传递2连接其分裂节点,现在Pass3(在XSLT2中 - 由于文件包含问题)的意图是分组/重新排列'清除' xml到SQL DDL中,但在pass3中没有识别任何内容。
顺便说一下,我试图通过 - NetBeansIDE(8.0.2) com.sun.org.apache.xalan.internal.xsltc.compiler.EqualityExpr "它只是在控制台上声明:例如编译错误: 不能转换为com.sun.org.apache.xalan.internal.xsltc.compiler.Pattern - NO FILE / LINE NUMBER CONTEXT-这个转换有多个文件,至少有三个pass,pass3似乎是我当前的问题。 现在详细说明 - 经过两次传递后,我看似格式良好的中间xml,我想进一步处理:(中间xml带有' Document / Body / Section / Segment'在实际的xml文件中)。
顺便提一下,下面的pass2输出提到了第一个Segment中的DB Table名称,后面有一个Table限定符,然后是第一个Column段中的列名,以及其余Seg段中的Row值:
<Document>
<Body>
<Section>
<Segment frags="1" size="32">
<Entry ycoord="1.40" xcoord="1.1" size="32" frags="1" desgn="Table">TEACHING AND LEARNING EXPERIENCE</Entry>
</Segment>
<Segment frags="1" size="25">
<Entry ycoord="2.40" xcoord="1.1" frags="1" size="25" desgn="Table">UNIVERSITY MODULES TAUGHT</Entry>
</Segment>
<Segment>
<Entry ycoord="3.40" xcoord="1.6" desgn="Column">Module(Full title and code – not abbreviated)</Entry>
<Entry ycoord="3.40" xcoord="2.6" desgn="Column">Level(Indicate year level, if graduate module, otherwise Honours or Masters)</Entry>
<Entry ycoord="3.40" xcoord="3.6" desgn="Column">University</Entry>
<Entry ycoord="3.40" xcoord="4.6" desgn="Column">From(mm/yyyy)</Entry>
<Entry ycoord="3.40" xcoord="5.6" desgn="Column">To(mm/yyyy)</Entry>
<Entry ycoord="3.40" xcoord="6.6" desgn="Column">Total period</Entry>
</Segment>
<Segment frags="7" size="87">
<Entry ycoord="4.40" xcoord="1.6 desgn="Column">Transport planning 201</Entry>
<Entry ycoord="4.40" xcoord="2.6" desgn="Column">Undergraduate</Entry>
<Entry ycoord="4.40" xcoord="3.6" desgn="Column">University of LLL</Entry>
<Entry ycoord="4.40" xcoord="4.6" desgn="Column">January 2011</Entry>
<Entry ycoord="4.40" xcoord="5.6" desgn="Column">-</Entry>
<Entry ycoord="4.40" xcoord="6.6" desgn="Column">3 years & 2Months</Entry>
</Segment>
<Segment frags="6" size="98">
<Entry ycoord="5.40" xcoord="1.6" desgn="Column">RI Planning 202</Entry>
<Entry ycoord="5.40" xcoord="2.6" desgn="Column">Undergraduate</Entry>
<Entry ycoord="5.40" xcoord="3.6" desgn="Column">University of LLL</Entry>
<Entry ycoord="5.40" xcoord="4.6" desgn="Column">January 2011</Entry>
<Entry ycoord="5.40" xcoord="5.6" desgn="Column">December 2012</Entry>
<Entry ycoord="5.40" xcoord="6.6" desgn="Column">2 years</Entry>
</Segment>
<Segment frags="6" size="96">
<Entry ycoord="6.40" xcoord="1.6" desgn="Column">LG and Civil Society</Entry>
<Entry ycoord="6.40" xcoord="2.6" desgn="Column">Undergraduate</Entry>
<Entry ycoord="6.40" xcoord="3.6" desgn="Column">University of LLL</Entry>
<Entry ycoord="6.40" xcoord="4.6" desgn="Column">July 2010</Entry>
<Entry ycoord="6.40" xcoord="5.6" desgn="Column">-</Entry>
<Entry ycoord="6.40" xcoord="6.6" desgn="Column">3 years & 7 Months</Entry>
</Segment>
<Segment frags="6" size="101">
<Entry ycoord="7.40" xcoord="1.6" desgn="Column">LGCS 242</Entry>
<Entry ycoord="7.40" xcoord="2.6" desgn="Column">UG/Entry>
<Entry ycoord="7.40" xcoord="3.6" desgn="Column">University of LLL</Entry>
<Entry ycoord="7.40" xcoord="4.6" desgn="Column">July 2010</Entry>
<Entry ycoord="7.40" xcoord="5.6" desgn="Column">December 2013</Entry>
<Entry ycoord="7.40" xcoord="6.6" desgn="Column">3 years</Entry>
</Segment>
</Section>
</Body>
</Document>
<xsl:transfrorm>
<xsl:template match="/" mode="pass2">
<xsl:variable name="pass2Out">
<xsl:apply-templates select="@* | node()" mode="pass2"/>
</xsl:variable>
<xsl:variable name="pass2Node" select="exslt:node-set($pass2Out)"/>
<xsl:apply-templates select="$pass2Node/*" mode="pass3"/>
</xsl:template>
<xsl:transform>
<xsl:transform>
<!-- ... -->
<xsl:template match="*" mode="pass3">
<xsl:copy>
<!-- have tried numerous other patterns to match here -->
<xsl:apply-templates mode="pass3" select="Document/Body/Section/Segment/Entry"/>
</xsl:copy>
</xsl:template>
<!-- one of many failed attempts at transforming pass2 output -->
<xsl:template match="Entry" mode="pass3">
<xsl:value-of select="local-name()"/>
<xsl:value-of select="@desgn"/>
<xsl:value-of select="."/>
</xsl:template>
</xsl:transform>
上述pass3转换尝试的结果未受影响;尽管额外的钩子可能同样有缺陷,但未列在此处。 PASS 3错过了一切,pass3输出完全如上所述。如何找出模板/模式/匹配有缺陷或错过的位置?
或者,如果可以显示如何匹配xml元素文本中包含的隐含数据库实体名称,为了生成适当的DDL子句,第一个错过匹配问题对我来说没有实际意义。
答案 0 :(得分:0)
我设法改变了上面的内容(在修复了谎言20和50中的拼写错误之后)&#34;并且缺少&lt;分别使用以下内容,但不作为包含文件(原始问题):
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:exslt="http://exslt.org/common"
exclude-result-prefixes="xsl exslt w aml wpc dt mc o v w10 wx wne wsp sl">
<xsl:output method="xml" encoding="utf-8" indent="yes"/>
<xsl:template match="/" mode="pass3">
<xsl:variable name="pass3Out">
<xsl:apply-templates select="@* | node()" mode="pass3"/>
</xsl:variable>
<xsl:variable name="pass3Node" select="exslt:node-set($pass3Out)"/>
<xsl:apply-templates select="$pass3Node/*" mode="pass4"/>
</xsl:template>
<xsl:template match="/" >
<xsl:apply-templates select="Document" mode="pass3"/>
</xsl:template>
<xsl:template match="Document" mode="pass3">
<xsl:copy>
<xsl:apply-templates select="Meta" />
<xsl:apply-templates select="Body/Logo" />
<xsl:apply-templates select="Body/Prelim" />
<xsl:apply-templates select="Body/Section" />
</xsl:copy>
</xsl:template>
<xsl:template match="Meta" >
<xsl:copy>
<xsl:apply-templates select="text()" />
</xsl:copy>
</xsl:template>
<xsl:template match="Body/Logo" >
<xsl:copy>
<xsl:apply-templates select="text()" />
</xsl:copy>
</xsl:template>
<xsl:template match="Segment" >
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:for-each select="Entry[not(@ycoord = preceding-sibling::Entry/@ycoord)]">
<xsl:variable name="Coord" select="@ycoord"/>
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:for-each select="../Entry[@ycoord = $Coord]">"<xsl:value-of select="."/>"</xsl:for-each>
</xsl:copy>
</xsl:for-each>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
获得:
<?xml version="1.0" encoding="utf-8"?>
<Document>
<Segment frags="1" size="32">
<Entry ycoord="1.40" xcoord="1.1" size="32" frags="1" desgn="Table">"TEACHING AND LEARNING EXPERIENCE"</Entry>
</Segment>
<Segment frags="1" size="25">
<Entry ycoord="2.40" xcoord="1.1" frags="1" size="25" desgn="Table">"UNIVERSITY MODULES TAUGHT"</Entry>
</Segment>
<Segment>
<Entry ycoord="3.40" xcoord="1.6" desgn="Column">"Module(Full title and code – not abbreviated)""Level(Indicate year level, if graduate module, otherwise Honours or Masters)""University""From(mm/yyyy)""To(mm/yyyy)""Total period"</Entry>
</Segment>
<Segment frags="7" size="87">
<Entry ycoord="4.40" xcoord="1.6" desgn="Column">"Transport planning 201""Undergraduate""University of LLL""January 2011""-""3 years & 2Months"</Entry>
</Segment>
<Segment frags="6" size="98">
<Entry ycoord="5.40" xcoord="1.6" desgn="Column">"RI Planning 202""Undergraduate""University of LLL""January 2011""December 2012""2 years"</Entry>
</Segment>
<Segment frags="6" size="96">
<Entry ycoord="6.40" xcoord="1.6" desgn="Column">"LG and Civil Society""Undergraduate""University of LLL""July 2010""-""3 years & 7 Months"</Entry>
</Segment>
<Segment frags="6" size="101">
<Entry ycoord="7.40" xcoord="1.6" desgn="Column">"LGCS 242""UG""University of LLL""July 2010""December 2013""3 years"</Entry>
</Segment>
</Document>
下一个HURDLE: 我需要在第一个Column Names行之后改变属性。 以下是我在文档pass4中遇到的问题(我省略了身份设计序言):
<xsl:template match="Segment" mode="pass4">
<xsl:copy>
<xsl:choose>
<xsl:when test="Entry[@desgn='Column'] and preceding-sibling::Entry[@desgn = 'Table']">
<xsl:for-each select="following-sibling::*/Entry[@desgn = 'Column']">
<xsl:copy-of select="@ycoord" /><xsl:copy-of select="@xcoord" />
<xsl:attribute name="desgn">RowVals</xsl:attribute>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="@*|node()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:copy>
</xsl:template>
除了text()之外,它除了简单替换&#39; Column&#39;与&#39; RowVals&#39;。任何帮助表示赞赏。