我把下面的混合文件集中在一个集合中。
B3:
<creditRisk>
<characteristic>
<score>
<LID>C230</LID>
<SPID>129587</SPID>
<Sector>Finance and Insurance</Sector>
</score>
<score>
<LID>C177</LID>
<SPID>360720</SPID>
<Sector>Mining and Oil and Gas Extraction</Sector>
</score>
</characteristic>
</creditRisk>
B4:
<creditRisk>
<pit>
<score>
<LID>C230</LID>
<SPID>129587</SPID>
<LTV>1.4689503</LTV>
<LGD>0.5995806998</LGD>
<Logarithm>-0.915243031</Logarithm>
</score>
<score>
<LID>C177</LID>
<SPID>360720</SPID>
<LTV>1.524224737</LTV>
<LGD>0.8989534312</LGD>
<Logarithm>-2.292173791</Logarithm>
</score>
</pit>
</creditRisk>为了简化这个问题,当pit/score@B4的SPID等于MarkLogic内的characteristic/score/SPID@B3时,我需要合并它。
预期产出:
<characteristic>
<score>
<default>
<LID>C230</LID>
<SPID>129587</SPID>
<LTV>1.4689503</LTV>
<LGD>0.5995806998</LGD>
<Logarithm>-0.915243031</Logarithm>
</default>
<LID>C230</LID>
<SPID>129587</SPID>
<Sector>Finance and Insurance</Sector>
</score>
<score>
<default>
<LID>C177</LID>
<SPID>360720</SPID>
<LTV>1.524224737</LTV>
<LGD>0.8989534312</LGD>
<Logarithm>-2.292173791</Logarithm>
</default>
<LID>C177</LID>
<SPID>360720</SPID>
<Sector>Mining and Oil and Gas Extraction</Sector>
</score>
</characteristic>我们正面临着问题。我的xsl结果都是空白的。
<xsl:template match="characteristic">
<characteristic>
<xsl:call-template name="scoreSPID">
<xsl:with-param name="characterScore" select="score"/>
</xsl:call-template>
</characteristic>
</xsl:template>
<xsl:template name="scoreSPID">
<xsl:param name="characterScore"/>
<xsl:for-each select="$characterScore">
<xsl:variable name="spid" select="SPID"/>
<score>
<xsl:for-each select="/creditRisk/pit/score[SPID eq $spid]">
<default>
<xsl:copy-of select="./node()"/>
</default>
<xsl:copy-of select="node()"/>
</xsl:for-each>
</score>
</xsl:for-each>
</xsl:template>
<xsl:template match="node()">
<xsl:apply-templates/>
</xsl:template>如何在xsl中获得匹配/合并工作?请注意,B3和B4在同一个数据库中是不同的功能。
发布于 2022-02-04 16:06:21
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fn="http://www.w3.org/2005/xpath-functions"
xmlns:cts="http://marklogic.com/cts" xmlns:fff="schema://fc.fasset/functions"
exclude-result-prefixes="#all" version="2.0">
<xsl:function name="fff:mergeModelI">
<xsl:param name="characterScore"/>
<xsl:for-each select="$characterScore">
<xsl:variable name="spid" select="SPID"/>
<xsl:variable name="query"
select="cts:path-range-query('/creditRisk/pit/score/SPID', '=', $spid)"/>
<xsl:variable name="model"
select="cts:search(fn:collection('collection-name')/creditRisk/pit/score, $query)"/>
<xsl:choose>
<xsl:when test="exists($model)">
<score>
<matched>merged</matched>
<default>
<xsl:copy-of select="$model/node()"/>
</default>
<xsl:copy-of select="node()"/>
</score>
</xsl:when>
<xsl:otherwise/>
</xsl:choose>
</xsl:for-each>
</xsl:function>
<xsl:template match="characteristic">
<characteristic>
<xsl:sequence select="fff:mergeModelI(score)"/>
</characteristic>
</xsl:template>
<xsl:template match="node()">
<xsl:apply-templates/>
</xsl:template>
</xsl:transform>如果您正在查看持续集成,则匹配/合并的文档应该被包含在具有不同集合的另一个数据库中。
上述和数据治理/审核需要匹配/合并操作跟踪。这里,我将<matched>merged</matched>标记为一种追索权。匹配/合并的文档可以基于标记在另一个数据库中填充。您可以设计更全面的规范化,以适应您的需要。
发布于 2022-02-01 04:20:54
在for -each的谓词筛选器中:
<xsl:for-each select="/creditRisk/pit/score[SPID eq spid]">您希望在SPID等于变量$spid的地方进行筛选。没有$,它正在寻找同级元素spid (它不存在)。
它应该是:
<xsl:for-each select="/creditRisk/pit/score[SPID eq $spid]">https://stackoverflow.com/questions/70931597
复制相似问题