我得到了像 < 这样的特殊字符p> 在数据中,需要像行一样格式化

I am getting special chars like <p> in data and need to be formatted like rows

提问人:Buddi 提问时间:11/15/2023 最后编辑:user207421Buddi 更新时间:11/16/2023 访问量:72

问:

我已将数据合并到一个元素中,但使用特殊字符获取数据。 例如:在下面的xml中,我得到了像field:一样的值。 这应该是如下的: 需要知道这样的原因。在上一步中,我使用 XSLT 将所有值合并为一个值。&lt;/p>&lt;p>&lt;span<PSQ2>

PSQ2 的期望值:

超越工作时间,满足发布时间表和其他优先事项。 在技能方面,我觉得他在技术上非常出色。在行为方面,他非常友好,让人觉得他是家庭成员中的一员。他以个人和专业的方式为人们提供建议。到目前为止,我还没有感觉到他保持双重想法。 他表现出分析问题、做出合理决策和克服问题的良好能力。一直在努力提高代码质量。

输入 XML:

<?xml version='1.0' encoding='UTF-8'?>
<wd:Report_Entry
    xmlns:wd="urn:com.workday/bsvc"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:is="java:com.workday.esb.intsys.xpath.ParsedIntegrationSystemFunctions"
    xmlns:xdiff="urn:com.workday/esb/xdiff">
    <empid>123</empid>
    <name>Ramu</name>
    <title>Software Architect</title>
    <manager>Ahmed</manager>
    <tempno>2</tempno>
    <MRQ2>&lt;p>Excellent technical knowledge, problem solving capabilities, team player&lt;/p></MRQ2>
    <DRQ2/>
    <PSQ2>&lt;p>Going beyond working hours to meet release timeline and other priority stuff.&lt;/p>&lt;p>Skill set wise, I feel he is technically very well sound. Behavior wise, he is very friendly, make people feel like he is one of a family member. He advices people in both personal and professional ways. So far I didn&amp;#39;t feel that he keeps double thoughts.&lt;/p>&lt;p>&lt;span>He has shown good ability to analyze issues, make sound decisions and overcome problems. Always trying to improve code quality. &lt;/span>&lt;/p></PSQ2>
    <MRQ3>&lt;p>Evangelize the design thinking, groom junior devs, create technical vision&lt;/p></MRQ3>
    <DRQ3/>
    <PSQ3>&lt;p>Keep your momentum and work towards making Conga Platform UI a great success.&lt;/p>&lt;p>I think he should learn how to be visible till the highest level. Like, he does many better things, however, I feel his visibility is not that much. Credits which should come to him are somehow going to somebody else. So he should learn how to present what he has done in such a way so that all deserved credits goes to him, everything that he does are acknowledged by higher management. This can be possible through better communication and presentation skills.&lt;/p>&lt;p>He can learn and try out new technology and different tools which can provide alternative to solve a problem in the most ideal way.&lt;/p></PSQ3>
    <MRQ4>9</MRQ4>
    <DRQ4_Min/>
    <DRQ4_Max/>
    <DRQ4_Median/>
    <PSQ4_Min>8</PSQ4_Min>
    <PSQ4_Max>9</PSQ4_Max>
    <PSQ4_Median>8.0</PSQ4_Median>
    <MRQ6>9</MRQ6>
    <DRQ6_Min/>
    <DRQ6_Max/>
    <DRQ6_Median/>
    <PSQ6_Min>6</PSQ6_Min>
    <PSQ6_Max>8</PSQ6_Max>
    <PSQ6_Median>8.0</PSQ6_Median>
</wd:Report_Entry>

为了获得上面的 xml,我使用下面的 XSLT 来组合数据。我不确定我是否在此 XSLT 中做错了:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:is="java:com.workday.esb.intsys.xpath.ParsedIntegrationSystemFunctions"
    xmlns:xdiff="urn:com.workday/esb/xdiff"
    xmlns:wd="urn:com.workday/bsvc">
    <xsl:output method="xml" indent="yes" omit-xml-declaration="no"/>
    
    <xsl:template match="/">
        <Report_Data>
            <xsl:apply-templates select="wd:Report_Data"/>
        </Report_Data>
    </xsl:template>
        
    <xsl:template match="wd:Report_Data">
        <xsl:for-each-group select="wd:Report_Entry" group-by="wd:empid">

            <Report_Entry>
            <empid>
            <xsl:value-of select="wd:empid"/>
            </empid>
                <name>
                    <xsl:value-of select="wd:name"/>
                </name>
                <title>
                    <xsl:value-of select="wd:title"/>
                </title>     
                <manager>
                    <xsl:value-of select="wd:manager"/>
                </manager>   
                <tempno>
                    <xsl:value-of select="wd:tempno"/>
                </tempno>                  
            <MRQ2>
            <xsl:for-each select="current-group()[wd:category = 'Manager' and wd:questionno='2' ]">
                <xsl:value-of select="wd:response"/>
            </xsl:for-each>
            </MRQ2>
            

                
                <DRQ2>
                                            <xsl:for-each select="current-group()[wd:category = 'Direct Report' and wd:questionno='2' ]">
                            <xsl:value-of select="wd:response"/>
                        </xsl:for-each>
                    
                </DRQ2>
                
            
            <PSQ2>
            <xsl:for-each select="current-group()[wd:category = 'Peer/Stakeholder' and wd:questionno='2' ]">
                <xsl:value-of select="wd:response"/>
            </xsl:for-each>
            </PSQ2>  
                
                <MRQ3>
                    <xsl:for-each select="current-group()[wd:category = 'Manager' and wd:questionno='3' ]">
                        <xsl:value-of select="wd:response"/>
                    </xsl:for-each>
                </MRQ3>
                
                
                
                <DRQ3>
                    <xsl:for-each select="current-group()[wd:category = 'Direct Report' and wd:questionno='3' ]">
                        <xsl:value-of select="wd:response"/>
                    </xsl:for-each>
                    
                </DRQ3>
                
                
                <PSQ3>
                    <xsl:for-each select="current-group()[wd:category = 'Peer/Stakeholder' and wd:questionno='3' ]">
                        <xsl:value-of select="wd:response"/>
                    </xsl:for-each>
                </PSQ3> 
                
                <MRQ4>
                    <xsl:for-each select="current-group()[wd:category = 'Manager' and wd:questionno='4' ]">
                        <xsl:value-of select="wd:response"/>
                    </xsl:for-each>
                </MRQ4>
                
                
                
                <DRQ4_Min>
                    <xsl:for-each select="current-group()[wd:category = 'Direct Report' and wd:questionno='4']">
                        <xsl:sort select="wd:response" data-type="number" order="ascending"/>
                        <xsl:if test="position() = 1">
                        <xsl:value-of select="wd:response"/>
                        </xsl:if>
                    </xsl:for-each>                    
                </DRQ4_Min>
                
                <DRQ4_Max>
                    <xsl:for-each select="current-group()[wd:category = 'Direct Report' and wd:questionno='4']">
                        <xsl:sort select="wd:response" data-type="number" order="descending"/>
                        <xsl:if test="position() = 1">
                            <xsl:value-of select="wd:response"/>
                        </xsl:if>
                    </xsl:for-each>                    
                </DRQ4_Max>
                
                <DRQ4_Median>
                    <xsl:for-each select="current-group()[wd:category = 'Direct Report' and wd:questionno='4']">
                        <xsl:sort select="wd:response" data-type="number" order="ascending"/>
                        <xsl:variable name="pos" select="position()"/>
                        <xsl:variable name="length" select="last()"/>
                        <xsl:if test="$pos = floor($length div 2) + 1">
                            <xsl:value-of select="format-number(sum(wd:response),'#.###')"/>
                        </xsl:if>
                    </xsl:for-each>                    
                </DRQ4_Median>
                
                
                <PSQ4_Min>
                    <xsl:for-each select="current-group()[wd:category = 'Peer/Stakeholder' and wd:questionno='4']">
                        <xsl:sort select="wd:response" data-type="number" order="ascending"/>
                        <xsl:if test="position() = 1">
                            <xsl:value-of select="wd:response"/>
                        </xsl:if>
                    </xsl:for-each>                    
                </PSQ4_Min>
                
                <PSQ4_Max>
                    <xsl:for-each select="current-group()[wd:category = 'Peer/Stakeholder' and wd:questionno='4']">
                        <xsl:sort select="wd:response" data-type="number" order="descending"/>
                        <xsl:if test="position() = 1">
                            <xsl:value-of select="wd:response"/>
                        </xsl:if>
                    </xsl:for-each>                    
                </PSQ4_Max>
                
                <PSQ4_Median>
                    <xsl:for-each select="current-group()[wd:category = 'Peer/Stakeholder' and wd:questionno='4']">
                        <xsl:sort select="wd:response" data-type="number" order="ascending"/>
                        <xsl:variable name="pos" select="position()"/>
                        <xsl:variable name="length" select="last()"/>
                        <xsl:if test="$pos = floor($length div 2) + 1">
                            <xsl:value-of select="format-number(sum(wd:response),'#.###')"/>
                        </xsl:if>
                    </xsl:for-each>                    
                </PSQ4_Median> 
            
                <MRQ6>
                    <xsl:for-each select="current-group()[wd:category = 'Manager' and wd:questionno='6' ]">
                        <xsl:value-of select="wd:response"/>
                    </xsl:for-each>
                </MRQ6>
                
                
                
                <DRQ6_Min>
                    <xsl:for-each select="current-group()[wd:category = 'Direct Report' and wd:questionno='6']">
                        <xsl:sort select="wd:response" data-type="number" order="ascending"/>
                        <xsl:if test="position() = 1">
                            <xsl:value-of select="wd:response"/>
                        </xsl:if>
                    </xsl:for-each>                    
                </DRQ6_Min>
                
                <DRQ6_Max>
                    <xsl:for-each select="current-group()[wd:category = 'Direct Report' and wd:questionno='6']">
                        <xsl:sort select="wd:response" data-type="number" order="descending"/>
                        <xsl:if test="position() = 1">
                            <xsl:value-of select="wd:response"/>
                        </xsl:if>
                    </xsl:for-each>                    
                </DRQ6_Max>
                
                <DRQ6_Median>
                    <xsl:for-each select="current-group()[wd:category = 'Direct Report' and wd:questionno='6']">
                        <xsl:sort select="wd:response" data-type="number" order="ascending"/>
                        <xsl:variable name="pos" select="position()"/>
                        <xsl:variable name="length" select="last()"/>
                        <xsl:if test="$pos = floor($length div 2) + 1">
                            <xsl:value-of select="format-number(sum(wd:response),'#.###')"/>
                        </xsl:if>
                    </xsl:for-each>                    
                </DRQ6_Median>
                
                
                <PSQ6_Min>
                    <xsl:for-each select="current-group()[wd:category = 'Peer/Stakeholder' and wd:questionno='6']">
                        <xsl:sort select="wd:response" data-type="number" order="ascending"/>
                        <xsl:if test="position() = 1">
                            <xsl:value-of select="wd:response"/>
                        </xsl:if>
                    </xsl:for-each>                    
                </PSQ6_Min>
                
                <PSQ6_Max>
                    <xsl:for-each select="current-group()[wd:category = 'Peer/Stakeholder' and wd:questionno='6']">
                        <xsl:sort select="wd:response" data-type="number" order="descending"/>
                        <xsl:if test="position() = 1">
                            <xsl:value-of select="wd:response"/>
                        </xsl:if>
                    </xsl:for-each>                    
                </PSQ6_Max>
                
                <PSQ6_Median>
                    <xsl:for-each select="current-group()[wd:category = 'Peer/Stakeholder' and wd:questionno='6']">
                        <xsl:sort select="wd:response" data-type="number" order="ascending"/>
                        <xsl:variable name="pos" select="position()"/>
                        <xsl:variable name="length" select="last()"/>
                        <xsl:if test="$pos = floor($length div 2) + 1">
                            <xsl:value-of select="format-number(sum(wd:response),'#.###')"/>
                        </xsl:if>
                    </xsl:for-each>                    
                </PSQ6_Median> 
            
            </Report_Entry>
            
        </xsl:for-each-group>

    </xsl:template>
</xsl:stylesheet>
XML XSLT XSLT-2.0

评论

0赞 michael.hor257k 11/15/2023
输入包含文本字符串和其他转义标记。您的 XSLT(您未显示)可能正在复制原始文本。在 XSLT 2.0 中,删除标记会很困难(在 XSLT 3.0 中可能更容易)。&lt;p>>&lt;/p>
0赞 LMC 11/15/2023
输入是一个 html 片段,该片段已转义以生成有效的 XML。需要解析以仅提取文本。
0赞 jdweng 11/15/2023
XML 和 HTML“有时”可以使用用于另一个的库进行解析。在大多数情况下,您需要使用 XML 库解析 Xml,并使用 HTML 库解析 HTML。
0赞 Buddi 11/15/2023
感谢大家的回复。我也发布了我的 XSLT,使用它来获取带有特殊字符的 xml 数据。我不确定我哪里做错了。
1赞 michael.hor257k 11/15/2023
你没有做错任何事情。您的数据提供者是。

答:

3赞 michael.hor257k 11/15/2023 #1

请看以下简化示例:

XML格式

<PSQ2>&lt;p>Going beyond working hours to meet release timeline and other priority stuff.&lt;/p>&lt;p>Skill set wise, I feel he is technically very well sound. Behavior wise, he is very friendly, make people feel like he is one of a family member. He advices people in both personal and professional ways. So far I didn&amp;#39;t feel that he keeps double thoughts.&lt;/p>&lt;p>&lt;span>He has shown good ability to analyze issues, make sound decisions and overcome problems. Always trying to improve code quality. &lt;/span>&lt;/p></PSQ2>

XSLT 3.0

<xsl:stylesheet version="3.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

<xsl:template match="PSQ2">
    <result>
        <xsl:value-of select="parse-xml-fragment(.)/p" />
    </result>
</xsl:template>

</xsl:stylesheet>

结果

<?xml version="1.0" encoding="UTF-8"?>
<result>Going beyond working hours to meet release timeline and other priority stuff. Skill set wise, I feel he is technically very well sound. Behavior wise, he is very friendly, make people feel like he is one of a family member. He advices people in both personal and professional ways. So far I didn't feel that he keeps double thoughts. He has shown good ability to analyze issues, make sound decisions and overcome problems. Always trying to improve code quality. </result>

该函数需要支持 XSLT 3.0 的处理器。如果没有这个,从转义标记中提取文本将更加困难。parse-xml-fragment()


添加:

将转义标记解析为 XML 后,可以按照您喜欢的任何方式将其处理为 XML - 例如:

<xsl:template match="PSQ2">
    <result>
        <xsl:for-each select="parse-xml-fragment(.)/p">
            <xsl:number format="1. "/>
            <xsl:value-of select="." />
            <xsl:text>&#10;</xsl:text>
        </xsl:for-each>
    </result>
</xsl:template>

将产生:

<result>1. Going beyond working hours to meet release timeline and other priority stuff.
2. Skill set wise, I feel he is technically very well sound. Behavior wise, he is very friendly, make people feel like he is one of a family member. He advices people in both personal and professional ways. So far I didn't feel that he keeps double thoughts.
3. He has shown good ability to analyze issues, make sound decisions and overcome problems. Always trying to improve code quality. 
</result>

评论

0赞 Buddi 11/15/2023
非常感谢。它真的帮助了我。我们可以根据您的结果或序列号显示段落等数据吗?我的意思是在第一条语句之后的下一行中显示数据。例如:1.超越工作时间以满足发布时间表和其他优先事项。2. 在技能方面,我觉得他在技术上非常出色。在行为方面,他非常友好,让人觉得他是家庭成员中的一员。他以个人和专业的方式为人们提供建议。到目前为止,我还没有感觉到他保持双重想法。3. 他表现出良好的分析问题、做出合理决策和克服问题的能力。
0赞 michael.hor257k 11/15/2023
请参阅我的答案的补充。
0赞 Buddi 11/15/2023
非常感谢你教这个。无论如何,我们随机显示语句(而不是我们的顺序)。例如:技能集明智的陈述是第一个。第二:他表现出了良好的质量声明,第三:向前迈进的工作声明。这可以随机保留吗?
0赞 Martin Honnen 11/15/2023
random-number-generator(current-dateTime())?permute(parse-xml-fragment(.)/p)
0赞 Buddi 11/15/2023
嗨,马丁,我正在寻找随机获取语句(不是数字生成器)。例如:技能集明智陈述是第一个。第二:他表现出了良好的质量声明,第三:向前迈进的工作声明