XSLT 1.0在某些条件下转换



我有一个XML,这是几个子系统查询的合并输出。现在,我必须选择很多信息。例如:

/MERGE/RENSIONS/BENUTZERDATEN/DEAKTIVIERT

如果/MERGE/RENSTYS/RESSIST/RESSIN/DN以",O = test,C = DE结束",只有一个结果以模式结尾:

/MERGE/RESPONS/RESPEST/RESCER/RESSER/attibutes/distiennummer

如果/merge/响应/结果/结果/DN以",dc = test,dc = de"结尾:

/MERGE/RESPONS/RESPEST/RESSION/RESLECT/属性/postalcode

最好的方法是什么?

这是我的Soure XML的简化样本:

<?xml version="1.0" encoding="UTF-8"?>
<Merge>
    <response>
        <results>
            <result>
                <dn>cn=user1,ou=members,ou=group1,o=test,c=de</dn>
                <attributes>
                    <identnummer>re3232</identnummer>
                    <uid>user1</uid>
                    [...]
                    <adminuid>admin3</adminuid>
                </attributes>
            </result>
        </results>
    </response>
    <response>
        <results>
            <result>
                <dn>CN=user1,OU=Users,DC=TEST,DC=DE</dn>
                <attributes>
                    <postalCode>12345</postalCode>
                    <company>My Company</company>
                    [...]
                    <streetAddress>XSLT Road 1</streetAddress>
                </attributes>
            </result>
        </results>
    </response>
    <response>
        <secDN>principalName=user1,cn=Users,secDomain=Default</secDN>
        <Benutzerdaten>
            <Deaktiviert>false</Deaktiviert>
            <Gesperrt>false</Gesperrt>
            [...]
            <PasswortGueltig>true</PasswortGueltig>
        </Benutzerdaten>
    </response>
    <Nutzdaten>
        <Identifikation>
            <AdminID>admin3</AdminID>
            <BenutzerID>user1</BenutzerID>
        </Identifikation>
        <Benutzerdaten>
            <Datentyp>Account-Daten</Datentyp>
            <Datentyp>Anwendungs-Daten</Datentyp>
            <Datentyp>Benutzer-Daten</Datentyp>
        </Benutzerdaten>
    </Nutzdaten>
</Merge>

预期的结果应该看起来像:

<?xml version="1.0" encoding="UTF-8"?>
<UserData>
    <user>user1</user>
    <source1>
        <identnummer>re3232</identnummer>
    </source1>
    <source2>
        <postalCode>12345</postalCode>
    </source2>
    <source3>
        <Deaktiviert>false</Deaktiviert>
    </source3>
</UserData>

这是我不成功的尝试:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
    <xsl:choose>
      <xsl:when test="/Merge/response/Benutzerdaten and count(/Merge/response/results/result[dn = '*,o=test,c=de') = 1"  and count(/Merge/response/results/result[dn = '*,DC=TEST,DC=DE') = 1" >
        <UserData>
          <user>
            <xsl:value-of select="/Merge/Nutzdaten/Identifikation/BenutzerID"/>
          </user>
          <xsl:if test="/Merge/response/Benutzerdaten/*">
            <Account>
              <xsl:copy-of select="/Merge/response/Benutzerdaten/*"/>
            </Account>
          </xsl:if>
          <xsl:if test="substring(/Merge/response/results/result/dn, string-length(/Merge/response/results/result/dn) -11) = ',o=test,c=de'">
            <source1>
                <postalCode>
                    <xsl:value-of select="/Merge/response/results/result/attributes/portalCode"></xsl:value-of>
                </postalCode>
            </source1>
          </xsl:if>
          <xsl:if test="substring(/Merge/response/results/result/dn, string-length(/Merge/response/results/result/dn) -12) = ',DC=TEST,DC=DE'">
            <source2>
                <postalCode>
                    <xsl:value-of select="/Merge/response/results/result/attributes/portalCode"></xsl:value-of>
                </postalCode>
            </source2>
          </xsl:if>
          <source3>
            <Deaktiviert>
                <xsl:value-of select="/Merge/response/BenutzerDaten/Deaktiviert"></xsl:value-of>
            </Deaktiviert>
          </source3>
        </UserData>
      </xsl:when>
      <xsl:otherwise>
        <response>
          <failure>
            <xsl:choose>
              <xsl:when test="count(/Merge/response/results/result[dn = '*,o=test,c=de') > 1">
                <message>more than one result from source1</message>
              </xsl:when>
              <xsl:otherwise>
                <message>The requested object does not exist.</message>
              </xsl:otherwise>
            </xsl:choose>
          </failure>
        </response>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
</xsl:stylesheet>

尝试以下:

    <xsl:param name="text" select="/Merge/response/results/result/dn[contains(text(),'o=test,c=de')]"/>
    <xsl:param name="text1" select="/Merge/response/results/result/dn[contains(text(),'DC=TEST,DC=DE')]"/>
    <xsl:choose>
        <xsl:when test="/Merge/response/Benutzerdaten and count(/Merge/response/results/result/dn [contains(text(),'o=test,c=de')]) = 1 and count(/Merge/response/results/result/dn[contains(text(),'DC=TEST,DC=DE')]) = 1" >
            <UserData>
                <user>
                    <xsl:value-of select="/Merge/Nutzdaten/Identifikation/BenutzerID"/>
                </user>
                <xsl:if test="/Merge/response/Benutzerdaten/*">
                    <Account>
                        <xsl:copy-of select="/Merge/response/Benutzerdaten/*"/>
                    </Account>
                </xsl:if>
                <xsl:if test="substring($text, string-length($text)-11)">
                    <source1>
                        <postalCode>
                            <xsl:value-of select="/Merge/response/results/result/attributes/portalCode"></xsl:value-of>
                        </postalCode>
                    </source1>
                </xsl:if>
                <xsl:if test="substring($text, string-length($text)-12)">
                    <source2>
                        <postalCode>
                            <xsl:value-of select="/Merge/response/results/result/attributes/postalCode"></xsl:value-of>
                        </postalCode>
                    </source2>
                </xsl:if>
                <source3>
                    <Deaktiviert>
                        <xsl:value-of select="/Merge/response/Benutzerdaten/Deaktiviert"></xsl:value-of>
                    </Deaktiviert>
                </source3>
            </UserData>
        </xsl:when>
        <xsl:otherwise>
            <response>
                <failure>
                    <xsl:choose>
                        <xsl:when test="count(/Merge/response/results/result/dn[contains(text(),'o=test,c=de')]) > 1">
                            <message>more than one result from source1</message>
                        </xsl:when>
                        <xsl:when test="count(/Merge/response/results/result/dn[contains(text(),'DC=TEST,DC=DE')]) > 1">
                            <message>more than one result from source2</message>
                        </xsl:when>
                        <xsl:otherwise>
                            <message>The requested object does not exist.</message>
                        </xsl:otherwise>
                    </xsl:choose>
                </failure>
            </response>
        </xsl:otherwise>
    </xsl:choose>

相关内容

  • 没有找到相关文章

最新更新