匹配子串中的 XSLT 分组
XSLT Grouping in Matching Substring
我正在为 xslt 做一个 unparsed-text()。所以数据来自文本文件
我需要获取元素 thistagwithsomeattributes
的结束标记作为 matching-string
中组的一部分,如下所示:
<xsl:template match="/" name="text2xml">
<xsl:variable name="entries" as="node()*">
<xsl:analyze-string select="$textfile" regex="\r\n?|\n">
<xsl:non-matching-substring>
<xsl:analyze-string select="." regex="someregcode">
<xsl:matching-substring>
<group>
<thistagwithsomeattributes>
<abc>some value coming from regex</abc>
<cde>some value from regex</cde>
</thistagwithsomeattributes>
</group>
</xsl:matching-substring>
</xsl:analyze-string>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:variable>
<xsl:for-each-group select="$entries" group-by="abc">
<final>
<xsl:copy-of
select="current-group()[1]/abc,current-group()/*[not(self::abc)]"/>
</final>
</xsl:for-each-group>
以上内容对我不起作用。如果我删除元素 thistagwithsomeattributes
,那么它就可以工作。如何将此元素作为匹配子字符串中组的一部分。我需要这个,因为这个元素的属性对于组
会有不同的值
What I'm trying to achieve (following XML structure):
<thistagwithsomeattributes att1="fromregexwithinggroup" att2="fromregexwithinggrouop">
<someelement>
<anothertagwithattributes att1="fromregexvalues">
<cont>
<itm>
abc>some value coming from regex</abc>
<cde>some value from regex</cde>
</itm>
</cont>
</anothertagwithattributes>
</thistagwithsomeattributes>
现在当我输入 <thistagwithsomeattributes>
和 <anothertagwithattributes>
时,它不起作用(没有结果),xml 文件是空的。但是当我删除它们时。我得到以下结果:
您需要将 <xsl:for-each-group select="$entries"
调整为 <xsl:for-each-group select="$entries/thistagwithsomeattributes"
。
我正在为 xslt 做一个 unparsed-text()。所以数据来自文本文件
我需要获取元素 thistagwithsomeattributes
的结束标记作为 matching-string
中组的一部分,如下所示:
<xsl:template match="/" name="text2xml">
<xsl:variable name="entries" as="node()*">
<xsl:analyze-string select="$textfile" regex="\r\n?|\n">
<xsl:non-matching-substring>
<xsl:analyze-string select="." regex="someregcode">
<xsl:matching-substring>
<group>
<thistagwithsomeattributes>
<abc>some value coming from regex</abc>
<cde>some value from regex</cde>
</thistagwithsomeattributes>
</group>
</xsl:matching-substring>
</xsl:analyze-string>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:variable>
<xsl:for-each-group select="$entries" group-by="abc">
<final>
<xsl:copy-of
select="current-group()[1]/abc,current-group()/*[not(self::abc)]"/>
</final>
</xsl:for-each-group>
以上内容对我不起作用。如果我删除元素 thistagwithsomeattributes
,那么它就可以工作。如何将此元素作为匹配子字符串中组的一部分。我需要这个,因为这个元素的属性对于组
What I'm trying to achieve (following XML structure):
<thistagwithsomeattributes att1="fromregexwithinggroup" att2="fromregexwithinggrouop">
<someelement>
<anothertagwithattributes att1="fromregexvalues">
<cont>
<itm>
abc>some value coming from regex</abc>
<cde>some value from regex</cde>
</itm>
</cont>
</anothertagwithattributes>
</thistagwithsomeattributes>
现在当我输入 <thistagwithsomeattributes>
和 <anothertagwithattributes>
时,它不起作用(没有结果),xml 文件是空的。但是当我删除它们时。我得到以下结果:
您需要将 <xsl:for-each-group select="$entries"
调整为 <xsl:for-each-group select="$entries/thistagwithsomeattributes"
。