2017-02-27 5 views
0

Ich fange gerade mit xsl an. Ich werde unten beschreiben, was ich zu erreichen versuche und hoffe, dass jemand helfen kann.Besuchsknoten in xsl

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> 
<ns1:GetSkillResponse> 
    <ns1:Skill> 
     <ns1:Person> 
      <ns1:SkillId>001</ns1:SkillId> 
     </ns1:Person> 
     <ns1:Task Active="N">Value 1</ns1:Task> 
     <ns1:Task Active="Y">Value 2</ns1:Task> 
     <ns1:Task Active="Y">Value 3</ns1:Task> 
    </ns1:Skill> 
    <ns1:Skill> 
     <ns1:Person> 
      <ns1:SkillId>002</ns1:SkillId> 
     </ns1:Person> 
     <ns1:Task Active="Y">Value 1</ns1:Task> 
     <ns1:Task Active="Y">Value 2</ns1:Task> 
     <ns1:Task Active="Y">Value 3</ns1:Task> 
    </ns1:Skill> 
</ns1:GetSkillResponse> 

<?xml version="1.0" encoding="UTF-16"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:ns1="http://test"> 
    <xsl:template name="GetSkillResponse"> 
     <Message> 
      <xsl:for-each select="/ns1:GetSkillResponse/ns1:Skill"> 
       <PropertySet> 
        <xsl:attribute name="MySkillId"><xsl:value-of select="ns1:Person/ns1:SkillId"/></xsl:attribute> 
        <xsl:attribute name="MyTask"><xsl:value-of select="ns1:Task"/></xsl:attribute> 
        <xsl:attribute name="MyActiveFlag"><xsl:value-of select="ns1:Task/@Active"/></xsl:attribute> 
       </PropertySet> 
      </xsl:for-each> 
     </Message> 
    </xsl:template> 
</xsl:stylesheet> 

Das bekommt mir:
001, 1 Wert, N
002, Wert 1, Y

Aber ich brauche zu bekommen:
001, Wert 1, N
001, Wert 2, Y
001, Wert 3, Y
002, Wert 1, Y
002, Wert 2, Y
00 2, Wert 3, Y

Ist das möglich?

Antwort

0

Es sieht so aus, als ob Sie für jedes Task Element unter Skill einen separaten Eintrag wünschen und dazu einfach eine verschachtelte xsl:for-each haben.

Zum Beispiel ...

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns1="http://test"> 
    <xsl:output method="xml" indent="yes" /> 

    <xsl:template match="/"> 
     <xsl:call-template name="GetSkillResponse" /> 
    </xsl:template> 

    <xsl:template name="GetSkillResponse"> 
     <Message> 
      <xsl:for-each select="/ns1:GetSkillResponse/ns1:Skill"> 
       <xsl:for-each select="ns1:Task"> 
        <PropertySet> 
         <xsl:attribute name="MySkillId"><xsl:value-of select="../ns1:Person/ns1:SkillId"/></xsl:attribute> 
         <xsl:attribute name="MyTask"><xsl:value-of select="."/></xsl:attribute> 
         <xsl:attribute name="MyActiveFlag"><xsl:value-of select="@Active"/></xsl:attribute> 
        </PropertySet> 
       </xsl:for-each> 
      </xsl:for-each> 
     </Message> 
    </xsl:template> 
</xsl:stylesheet> 

Hinweis Sie diese mit Attribute Value Templates

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns1="http://test"> 
    <xsl:output method="xml" indent="yes" /> 

    <xsl:template match="/"> 
     <xsl:call-template name="GetSkillResponse" /> 
    </xsl:template> 

    <xsl:template name="GetSkillResponse"> 
     <Message> 
      <xsl:for-each select="/ns1:GetSkillResponse/ns1:Skill"> 
       <xsl:for-each select="ns1:Task"> 
        <PropertySet MySkillId="{../ns1:Person/ns1:SkillId}" MyTask="{.}" MyActiveFlag="{@Active}"/> 
       </xsl:for-each> 
      </xsl:for-each> 
     </Message> 
    </xsl:template> 
</xsl:stylesheet> 
+0

Vielen Dank vereinfachen können, ist dies genau das, was ich brauchte. – Paul