-1

xml と xslt にクエリがあります

以下は入力 XML です。

<?xml version="1.0" encoding="UTF-8"?>    
<Employer>
<Employees>
    <EmployeesDetails>van ind 26%</EmployeesDetails>
</Employees>    
<Employees>
    <EmployeesDetails>van ind</EmployeesDetails>
</Employees>    

以下は私の出力ファイルです

<?xml version="1.0" encoding="UTF-8"?>
<Employer>
<Employees>
    <Names>van</Names>
    <Location>ind</Location>                
    <Weather>26</Weather>
</Employees>
<Employees>
    <Names>van</Names>
    <Location>ind</Location>
    <Weather>100</Weather>
</Employees>

XSLT では、入力 XML から天気要素が利用可能かどうか (XSL:IF) を確認する必要があります (26%) XSLT を使用して % を削除する必要がある場合、出力は 26 になります。XML に要素がない場合 (天気)デフォルトでは 100 を作成する必要があります。

XSLT でこれを行うことができるかどうかは、可能です。

誰でもここで私を助けてくれますか

4

1 に答える 1

0

次のXSLTをご覧ください。

<?xml version="1.0" encoding="utf-16"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output omit-xml-declaration="yes" indent="yes" />

    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates />
        </xsl:copy>
    </xsl:template>

    <xsl:template match="EmployeesDetails">
        <xsl:variable name="Detail" select="concat(., ' ')" />
        <xsl:variable name="Names" select="substring-before($Detail, ' ')" />
        <xsl:variable name="Location" select="substring-before(substring-after($Detail, concat($Names, ' ')), ' ')" />
        <xsl:variable name="Weather" select="substring-before(substring-after($Detail, concat($Location, ' ')), '% ')" />
        <Names>
            <xsl:value-of select="$Names" />
        </Names>
        <Location>
            <xsl:value-of select="$Location" />
        </Location>
        <Weather>
            <xsl:choose>
                <xsl:when test="string-length($Weather) &gt; 0">
                    <xsl:value-of select="$Weather" />
                </xsl:when>
                <xsl:otherwise>100</xsl:otherwise>
            </xsl:choose>
        </Weather>
    </xsl:template>
</xsl:stylesheet>

http://www.xmlplayground.com/Gg5F3z

于 2012-07-09T05:00:51.750 に答える