提问人:TulioVargas 提问时间:11/13/2023 最后编辑:Michael KayTulioVargas 更新时间:11/13/2023 访问量:42
如果找到相同的标记名称,则具有角色的 XSLT 转换pf
XSLT transformation with role if find the same tag namepf
问:
我正在进行 XSLT 转换,在实现特定转换逻辑方面需要帮助。以下是详细信息:
目的:
如果不同元素的标签相同,我想将标签中的错误连接起来。<namepf>
<record>
<errors>
输入 XML
<root>
<record msg="File with error." status="ERROR" task="AD_CLT - Hiring/CLT">
<client>4039</client>
<company>84046101038328</company>
<indcnp>1</indcnp>
<namepf>Peter Santos</namepf>
<ticket>A4039</ticket>
<action>Save</action>
<task>AD_CLT</task>
<datenv error="Invalid registration." status="ERROR">01/11/2023</datenv>
<horenv>09:15</horenv>
<usuenv>34950</usuenv>
<usubpo error="Invalid registration. 123" status="ERROR">Blenn-WEBSERVICE</usubpo>
<indide>2</indide>
<nreqid>HI0111091515290</nreqid>
<idempr>01062748565</idempr>
<idglob>69733</idglob>
<matric error="Invalid registration. Next available number 2569999. ticket: 123 by employee 2569733." status="ERROR">2569733</matric>
<tpRJor>1</tpRJor>
<dataso>23/10/2023</dataso>
<nromed>7749</nromed>
<ufmed>GO</ufmed>
</record>
<record msg="File with error." status="ERROR" task="AD_CLT - Hiring/CLT">
<client>4039</client>
<company>84046101038328</company>
<indcnp>1</indcnp>
<ticket>A4039</ticket>
<action>Save</action>
<namepf>Peter Santos</namepf>
<horenv>09:15</horenv>
<usuenv>34950</usuenv>
<usubpo error="Invalid registration. 123" status="ERROR">Blenn-WEBSERVICE</usubpo>
<indide>2</indide>
<nreqid>HI0111091515290</nreqid>
<idempr error="Invalid registration. 456" status="ERROR">01062748565</idempr>
<idglob error="Invalid registration. 789" status="ERROR">69733</idglob>
<tpRJor>1</tpRJor>
<dataso>23/10/2023</dataso>
<nromed>7749</nromed>
<ufmed>GO</ufmed>
</record>
</root>
所需的输出 XML:
<emailTitle><![CDATA[<record msg="File with error." status="ERROR" task="AD_CLT - Hiring/CLT">]]></emailTitle>
<name>namepf: Peter Santos</name>
<errors>
<datenv error="Invalid registration." status="ERROR">01/11/2023</datenv>
<usubpo error="Invalid registration. 123" status="ERROR">Blenn-WEBSERVICE</usubpo>
<matric error="Invalid registration. Next available number 2569999. ticket: 123 by employee 2569733." status="ERROR">2569733</matric>
<task error="Invalid registration. 123" status="ERROR">AD_CLT</task>
<idempr error="Invalid registration. 456" status="ERROR">01062748565</idempr>
<idglob error="Invalid registration. 789" status="ERROR">69733</idglob>
</errors>
</root>
我从基本的 XSLT 开始,它对于复制状态属性为“ERROR”的元素很有用。但是,需要提出建议或修改来处理具有相同 . 的记录的错误串联。<namepf>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<!-- Match the root element -->
<xsl:template match="root">
<xsl:copy>
<!-- Apply templates to child elements -->
<xsl:apply-templates select="record[@status='ERRO']"/>
</xsl:copy>
</xsl:template>
<!-- Match the 'record' element -->
<xsl:template match="record">
<xsl:copy>
<!-- Copy 'record' attributes -->
<xsl:copy-of select="@*"/>
<!-- Apply templates to child elements with error status -->
<xsl:apply-templates select="*[@status='ERRO']"/>
</xsl:copy>
</xsl:template>
<!-- Match elements with error status -->
<xsl:template match="*[not(self::record) and @status='ERRO']">
<xsl:copy>
<!-- Copy element attributes -->
<xsl:copy-of select="@*"/>
<!-- Copy element text content -->
<xsl:copy-of select="text()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
答: 暂无答案
评论
xsl:for-each-group select="record" group-by="namepf"
xslt-grouping