0

これはかなり単純に思えますが、必要な出力を生成することができません。どんな助けでも大歓迎です。

入力 XML:

<?xml version="1.0" encoding="UTF-8"?>
<Event xmlns="urn:sobject.partner.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Id>00Uc0000001iioEEAQ</Id>
<Subject>TestMeeting2</Subject>
<StartDateTime xsi:nil="true"/>
<Owner>
    <Name>dev0044</Name>
    <Email>testuser0044@gmail.com</Email>
</Owner>
<Notes_Universal_ID__c xsi:nil="true"/>
<Location>San Jose</Location>
<IsPrivate>false</IsPrivate>
<IsDeleted>false</IsDeleted>
<EndDateTime xsi:nil="true"/>
<Description>test description</Description>
<EventRelations>
    <EventRelation>
        <EventId>00Uc0000001iioEEAQ</EventId>
        <RelationId>005c0000000T9YQAA0</RelationId>
        <Relation>
            <Email>testuser0045@gmail.com</Email>
        </Relation>
    </EventRelation>
    <EventRelation>
        <EventId>00Uc0000001iioEEAQ</EventId>
        <RelationId>005c0000000T9YaAAK</RelationId>
        <Relation>
            <Email>testuser0047@gmail.com</Email>
        </Relation>
    </EventRelation>
</EventRelations>

必要な出力 XML:

<?xml version="1.0" encoding="UTF-8"?>
<CREATEAPPOINTMENT>
<STRUSERNAME>testuser0044</STRUSERNAME>
<STRSTARTDATETIME/>
<STRENDDATETIME/>
<STRSUBJECT>TestMeeting2</STRSUBJECT>
<STRDESCRIPTION>Email : testuser0045@gmail.com, testuser0047@gmail.com. Description:    test description</STRDESCRIPTION>
<SRTLOCATION>San Jose</SRTLOCATION>
<STRPRIVATE>0</STRPRIVATE>
<STRAVAILABLE>0</STRAVAILABLE>
</CREATEAPPOINTMENT>

説明フィールドを除くすべてを取得できます。STRDESCRIPTION には、EventRelations/EventRelation/Relation/Email (コンマ区切りの電子メール アドレス) と実際の説明フィールドの連結が含まれます。

これが私が試しているxslです:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0" 
xmlns:sf="urn:partner.soap.sforce.com" 
xmlns:xs="http://www.w3.org/2001/XMLSchema" 
xmlns:bpws="http://schemas.xmlsoap.org/ws/2003/03/business-process/">
<xsl:output indent="yes" method="xml"/>

<xsl:template match="*:Event">
    <xsl:element name="CREATEAPPOINTMENT">
        <xsl:element name="STRUSERNAME"><xsl:value-of select="*:Owner/*:Name"/></xsl:element>
        <xsl:element name="STRSTARTDATETIME"><xsl:value-of select="*:StartDateTime"/></xsl:element>
        <xsl:element name="STRENDDATETIME"><xsl:value-of select="*:EndDateTime"/></xsl:element>
        <xsl:element name="STRSUBJECT"><xsl:value-of select="*:Subject"/></xsl:element>
        <xsl:variable name="description" select="*:Description"/>

        <xsl:element name="SRTDESCRIPTION">
        <xsl:for-each select="*:EventRelations/*:EventRelation">
            <xsl:variable name="email" select="*:Relation/*:Email"/>
                <!-- <xsl:value-of select="concat('Email : ', $email, ' : Description : ')"></xsl:value-of> -->
            <xsl:value-of select="$email"/>
            <xsl:text>, </xsl:text>
            <xsl:value-of select="$description"></xsl:value-of>
            <xsl:text>, </xsl:text>
        </xsl:for-each>
        </xsl:element>

        <xsl:element name="SRTLOCATION"><xsl:value-of select="*:Location"/></xsl:element>

        <xsl:choose>
            <xsl:when test="*:IsPrivate = 'false'">
                <xsl:element name="STRPRIVATE">0</xsl:element>
            </xsl:when>
            <xsl:otherwise>
                <xsl:element name="STRPRIVATE">1</xsl:element>
            </xsl:otherwise>
        </xsl:choose>

        <xsl:choose>
            <xsl:when test="*:IsPrivate = 'false'">
                <xsl:element name="STRAVAILABLE">0</xsl:element>
            </xsl:when>
            <xsl:otherwise>
                <xsl:element name="STRAVAILABLE">1</xsl:element>
            </xsl:otherwise>
        </xsl:choose>

    </xsl:element>
</xsl:template>

4

1 に答える 1

1

separatorXSLT 2.0 を使用しているため、 の属性を使用できますxsl:value-of。を使用することもできるので、プレフィックスとしてxpath-default-namespace使用する必要はありません。*

例:

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xpath-default-namespace="urn:sobject.partner.soap.sforce.com">
    <xsl:output indent="yes"/>
    <xsl:strip-space elements="*"/>

    <xsl:template match="text()"/>

    <xsl:template match="/*">
        <CREATEAPPOINTMENT>
            <xsl:apply-templates select="(Owner,StartDateTime,EndDateTime,
                Subject,Description,Location,IsPrivate)"/>
        </CREATEAPPOINTMENT>
    </xsl:template>

    <xsl:template match="Owner/Name">
        <STRUSERNAME><xsl:value-of select="."/></STRUSERNAME>
    </xsl:template>

    <xsl:template match="StartDateTime">
        <STRSTARTDATETIME><xsl:value-of select="."/></STRSTARTDATETIME>
    </xsl:template>

    <xsl:template match="EndDateTime">
        <STRENDDATETIME><xsl:value-of select="."/></STRENDDATETIME>
    </xsl:template>

    <xsl:template match="Subject">
        <STRSUBJECT><xsl:value-of select="."/></STRSUBJECT>
    </xsl:template>

    <xsl:template match="Description">
        <STRDESCRIPTION>
            <xsl:text>Email: </xsl:text>
            <xsl:value-of select="../EventRelations/*/Relation/Email" separator=", "/>
            <xsl:text> DESCRIPTION: </xsl:text>
            <xsl:value-of select="."/>
        </STRDESCRIPTION>
    </xsl:template>

    <xsl:template match="Location">
        <SRTLOCATION><xsl:value-of select="."/></SRTLOCATION>
    </xsl:template>

    <xsl:template match="IsPrivate">
        <STRPRIVATE><xsl:apply-templates/></STRPRIVATE>
        <STRAVAILABLE><xsl:apply-templates/></STRAVAILABLE>
    </xsl:template>

    <xsl:template match="IsPrivate/text()">
        <xsl:choose>
            <xsl:when test=".='false'"><xsl:text>0</xsl:text></xsl:when>
            <xsl:otherwise><xsl:text>1</xsl:text></xsl:otherwise>
        </xsl:choose>
    </xsl:template>

</xsl:stylesheet>

出力

<CREATEAPPOINTMENT>
   <STRUSERNAME>dev0044</STRUSERNAME>
   <STRSTARTDATETIME/>
   <STRENDDATETIME/>
   <STRSUBJECT>TestMeeting2</STRSUBJECT>
   <STRDESCRIPTION>Email: testuser0045@gmail.com, testuser0047@gmail.com DESCRIPTION: test description</STRDESCRIPTION>
   <SRTLOCATION>San Jose</SRTLOCATION>
   <STRPRIVATE>0</STRPRIVATE>
   <STRAVAILABLE>0</STRAVAILABLE>
</CREATEAPPOINTMENT>

注: 要素の順序は、質問の出力とは異なります。順序が重要な場合は、順序を指定するテンプレートの に を追加できますselect。(参考になれば修正します。)xsl:apply-templates/*

StartDateTimeまた、先頭に「STR」を追加して新しい要素を作成する場合は、 、EndDateTimeSubject、およびのテンプレートを次のように置き換えることができますLocation

<xsl:template match="StartDateTime|EndDateTime|Subject|Location">
    <xsl:element name="STR{upper-case(local-name())}">
        <xsl:value-of select="."/>
    </xsl:element>
</xsl:template>
于 2013-06-13T18:26:49.603 に答える