2017-05-29 1 views
0

Hallo Community, ich habe eine XSLT und eine XML, die ich in eine andere XSLT konvertieren möchte.XSLT Transformator - Anrufvorlage falsche Position

Skript 1: Enthält eine Common.xslt, in der Vorlagen gespeichert sind. Script 2: Common

Wenn ich laufen diese xml die Ausgabe wie folgt lautet:

<?xml version="1.0" encoding="UTF-8"?> 


<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> 
    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" omit-xml-declaration="yes"/> 
    <xsl:template match="*[local-name()='Payload']"> 
     <xsl:variable name="countElements"> 
      <xsl:value-of select="count(//../SRBE)"/> 
     </xsl:variable> 
    </xsl:template> 
</xsl:stylesheet> 
<xsl:element xmlns:xsl="http://www.w3.org/1999/XSL/Transform" name="OperatorCode"> 
    <xsl:attribute name="type">Data</xsl:attribute> 
    <xsl:value-of select="SRBE/OperatorCode"/> 
</xsl:element> 

, aber ich brauche die Ausgabe wie folgt aus:

<?xml version="1.0" encoding="UTF-8"?> 


<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> 
    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" omit-xml-declaration="yes"/> 
    <xsl:template match="*[local-name()='Payload']"> 
     <xsl:variable name="countElements"> 
      <xsl:value-of select="count(//../SRBE)"/> 
     </xsl:variable> 
<xsl:element xmlns:xsl="http://www.w3.org/1999/XSL/Transform" name="OperatorCode"> 
    <xsl:attribute name="type">Data</xsl:attribute> 
    <xsl:value-of select="SRBE/OperatorCode"/> 
</xsl:element> 
    </xsl:template> 
</xsl:stylesheet> 

SCRIPT 1:

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> 
    <xsl:include href="common.xslt"></xsl:include> 
    <xsl:template match="*[local-name()='Mask']"> 
     <!-- set path --> 
     <xsl:param name="path" select="./Interface"></xsl:param> 
     <xsl:call-template name="common"></xsl:call-template> 

     <!-- check if mask is an SRBE --> 
     <xsl:if test="$mask = 'SRBE'"> 
      <!-- iterate over all Field elements --> 
      <xsl:for-each select="$path/Field"> 
       <!-- set variable fieldName with exploded Field Name --> 
       <xsl:variable name="fieldName"> 
        <xsl:value-of select="substring-after(./@Name, '/')"></xsl:value-of> 
       </xsl:variable> 

       <!-- switch case start if maxoccurs is set or not --> 
       <xsl:choose> 
        <!-- if maxoccurs is set and greater then 1 --> 
        <xsl:when test="./Son/@MaxOccurs and ./Son/@MaxOccurs > 1"> 

         <!-- manually field sets --> 
         <xsl:if test="$fieldName = 'FreeFormatLine'"> 
          <xsl:call-template name="tablePageBreak"> 
           <xsl:with-param name="fieldName"><xsl:value-of select ="$fieldName"/></xsl:with-param> 
           <xsl:with-param name="wrapperName">Line</xsl:with-param> 
          </xsl:call-template> 
         </xsl:if> 
        </xsl:when> 


        <xsl:otherwise> 
         <!-- call singleFields template --> 
         <xsl:call-template name="singleFields"> 
          <!-- set params --> 
          <xsl:with-param name="fieldName"><xsl:value-of select ="$fieldName"/></xsl:with-param> 
         </xsl:call-template> 

        </xsl:otherwise> 
       </xsl:choose> 

      </xsl:for-each> 

     </xsl:if> 
    </xsl:template> 
</xsl:stylesheet> 

SCRIPT 2:

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

    <!-- set variable "MASK" with service name--> 
    <xsl:variable name="mask"> 
     <xsl:value-of select="*[local-name()='Repository']/@Name"></xsl:value-of> 
    </xsl:variable> 

    <!-- start of standart template ~Mask --> 
    <xsl:template name="common"> 
     <!-- create pseudo stylesheet --> 
     <xsl:element name="xsl:stylesheet"> 
      <xsl:attribute name="version">1.0</xsl:attribute> 

      <!-- create pseudo xsl output with attributes --> 
      <xsl:element name="xsl:output"> 
       <xsl:attribute name="method">xml</xsl:attribute> 
       <xsl:attribute name="version">1.0</xsl:attribute> 
       <xsl:attribute name="encoding">UTF-8</xsl:attribute> 
       <xsl:attribute name="indent">yes</xsl:attribute> 
       <xsl:attribute name="omit-xml-declaration">yes</xsl:attribute> 
      </xsl:element> 

      <!-- create pseudo xsl template --> 
      <xsl:element name="xsl:template"> 
       <xsl:attribute name="match">*[local-name()='Payload']</xsl:attribute> 

       <xsl:element name="xsl:variable"> 
        <xsl:attribute name="name">countElements</xsl:attribute> 
        <xsl:element name="xsl:value-of"> 
         <xsl:attribute name="select">count(//../<xsl:value-of select="$mask"/>)</xsl:attribute> 
        </xsl:element> 
       </xsl:element> 



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

    <!-- template for table sbre output --> 
    <xsl:template name="tablePageBreak"> 
     <xsl:param name="fieldName" /> 
     <xsl:param name="wrapperName" /> 

     <!-- pseudo foreach mask name tag | multiple e.g. SRBE'S--> 
     <xsl:element name="xsl:for-each"> 
      <xsl:attribute name="select">//*[local-name()='<xsl:value-of select="$mask"></xsl:value-of>']</xsl:attribute> 

      <!-- pseudo create variable | get position --> 
      <xsl:element name="xsl:variable"> 
       <xsl:attribute name="name">srbeId</xsl:attribute> 
       <xsl:element name="xsl:value-of"> 
        <xsl:attribute name="select">position()</xsl:attribute> 
       </xsl:element> 
      </xsl:element> 

      <!-- pseudo create variable | count all lines in mask name tag --> 
      <xsl:element name="xsl:variable"> 
       <xsl:attribute name="name">lines</xsl:attribute> 
       <xsl:element name="xsl:value-of"> 
        <xsl:attribute name="select">count(./<xsl:value-of select="$fieldName"></xsl:value-of>)</xsl:attribute> 
       </xsl:element> 
      </xsl:element> 

      <!-- pseudo create table wrapper --> 
      <xsl:element name="xsl:element"> 
       <xsl:attribute name="name">Document</xsl:attribute> 
       <!-- pseudo add type attribute with "Table" --> 
       <xsl:element name="xsl:attribute"><xsl:attribute name="name">Type</xsl:attribute>Table</xsl:element> 
       <!-- pseudo create DocumentType Number Element --> 
       <xsl:element name="xsl:element"> 
        <xsl:attribute name="name">DocumentTypeNumber</xsl:attribute> 
        <xsl:element name="xsl:attribute"><xsl:attribute name="name">type</xsl:attribute>Data</xsl:element> 
        <!-- pseudo fill DocumentTypeNumber with Information --> 
        <xsl:element name="xsl:value-of"> 
         <xsl:attribute name="select">concat(../PrintHeader/barcode,../PrintHeader/ticketNo)</xsl:attribute> 
        </xsl:element> 
       </xsl:element> 
       <!-- pseudo for each -> iterate all fields --> 
       <xsl:element name="xsl:for-each"> 
        <xsl:attribute name="select">./<xsl:value-of select="$fieldName"></xsl:value-of></xsl:attribute> 
        <!-- pseudo create element with $fieldName as Tag --> 
        <xsl:element name="xsl:element"> 
         <xsl:attribute name="name"><xsl:value-of select="$wrapperName"></xsl:value-of></xsl:attribute> 
         <xsl:element name="xsl:attribute"><xsl:attribute name="name">Type</xsl:attribute>Table</xsl:element> 
         <xsl:element name="xsl:element"> 
          <xsl:attribute name="name"><xsl:value-of select="$fieldName"></xsl:value-of></xsl:attribute> 
          <xsl:element name="xsl:value-of"> 
           <xsl:attribute name="select">.</xsl:attribute> 
          </xsl:element> 
         </xsl:element> 
         <!-- pseudo if: if not last mask element and if last subelement --> 
         <xsl:element name="xsl:if"> 
          <xsl:attribute name="test">$countElements != $srbeId and $lines = position()</xsl:attribute> 
          <xsl:element name="xsl:element"> 
           <xsl:attribute name="name">TurnPageAfter</xsl:attribute> 
           <xsl:element name="xsl:value-of"> 
            <xsl:attribute name="select">number(substring-before(../Page, '/'))</xsl:attribute> 
           </xsl:element> 
          </xsl:element> 
         </xsl:element> 
        </xsl:element> 

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

    <!-- template for table output --> 
    <xsl:template name="table"> 
     <xsl:param name="fieldName" /> 
     <xsl:param name="wrapperName" /> 

     <!-- pseudo foreach mask name tag --> 
     <xsl:element name="xsl:for-each"> 
      <xsl:attribute name="select">//*[local-name()='<xsl:value-of select="$mask"></xsl:value-of>']</xsl:attribute> 

      <!-- pseudo for each -> iterate all fields --> 
       <xsl:element name="xsl:for-each"> 
        <xsl:attribute name="select">./<xsl:value-of select="$fieldName"></xsl:value-of></xsl:attribute> 
        <!-- pseudo create element with $fieldName as Tag --> 
        <xsl:element name="xsl:element"> 
         <xsl:attribute name="name"><xsl:value-of select="$wrapperName"></xsl:value-of></xsl:attribute> 
         <xsl:element name="xsl:attribute"><xsl:attribute name="name">Type</xsl:attribute>Table</xsl:element> 
         <xsl:element name="xsl:element"> 
          <xsl:attribute name="name"><xsl:value-of select="$fieldName"></xsl:value-of></xsl:attribute> 
          <xsl:element name="xsl:value-of"> 
           <xsl:attribute name="select">.</xsl:attribute> 
          </xsl:element> 
         </xsl:element> 
        </xsl:element> 

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

    <!-- template for count up input fields--> 
    <xsl:template name="countUp"> 
     <xsl:param name="fieldName" /> 

     <xsl:element name="xsl:for-each"> 
      <xsl:attribute name="select"><xsl:value-of select="$mask"/>/<xsl:value-of select="$fieldName"></xsl:value-of></xsl:attribute> 
      <xsl:element name="xsl:element"> 

       <xsl:attribute name="name"><xsl:value-of select="$fieldName"/>_{position()}</xsl:attribute> 
       <xsl:element name="xsl:attribute"><xsl:attribute name="name">type</xsl:attribute>Data</xsl:element> 
       <xsl:element name="xsl:value-of"> 
        <xsl:attribute name="select">.</xsl:attribute> 
       </xsl:element> 
      </xsl:element> 
     </xsl:element> 
    </xsl:template> 

    <!-- template for single input fields--> 
    <xsl:template name="singleFields"> 
     <xsl:param name="fieldName" /> 

     <!-- create element for creating fieldName element --> 
     <xsl:element name="xsl:element"> 
      <xsl:attribute name="name"> 
       <xsl:if test="$fieldName != 'Page'"> 
        <xsl:value-of select="$fieldName"></xsl:value-of> 
       </xsl:if> 
       <xsl:if test="$fieldName = 'Page'">Pages</xsl:if> 
      </xsl:attribute> 

      <xsl:element name="xsl:attribute"> 
       <xsl:attribute name="name">type</xsl:attribute>Data</xsl:element> 


      <!-- create element for creating value-of -> fill content --> 
      <xsl:element name="xsl:value-of"> 
       <xsl:if test="$fieldName != 'Page'"> 
        <xsl:attribute name="select"><xsl:value-of select="$mask"/>/<xsl:value-of select="$fieldName"/></xsl:attribute> 
       </xsl:if> 
       <xsl:if test="$fieldName = 'Page'"> 
        <xsl:attribute name="select">number(substring-after(<xsl:value-of select="$mask"/>/<xsl:value-of select="$fieldName"/>, '/'))</xsl:attribute> 
       </xsl:if> 
      </xsl:element> 

     </xsl:element> 

    </xsl:template> 



</xsl:stylesheet> 

XML:

<?xml version="1.0" encoding="iso-8859-1"?> 
<Repository xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Name="SRBE" Version="1" Language="de"> 
<BOMTHeader PartnerName="PRNT" ExternalProtocol="XML" InternalProtocol="Datastream" RepositoryComment="" IdentifierNestingLevel="0" IdentifierType="P" VersionNestingLevel="0" VersionType="B" IdentifierElementValue="Name"/> 
<STARTMasks> 
<Mask lang="de" Name="SRBE" Version="1" Barcode="75" DynamicPrint="1"> 
<Interface> 
    <Service Name="SRBE" Version="1" NoSel="1"> 
     <Segment Name="TOPLEVELTAG" Version="01" OmtSort="1" UsedByOmt="1" /> 
     <Segment Name="PrintHeaderAcp" Version="01" OmtSort="2" UsedByOmt="1" /> 
     <Segment Name="PrintHeader" Version="01" OmtSort="3" UsedByOmt="1" /> 
     <Segment Name="SRBE" Mandatory="1" Main="1" OmtSort="4" UsedByOmt="1" /> 
    </Service> 
<Field Name="SRBE/OperatorCode" > 
<Position Row="0" Col="2" Len="13" /> 
    <Son Name="vermittler_veran" SonSort="1" /> 
</Field> 
<Field Name="SRBE/OperatorName" > 
<Position Row="0" Col="16" Len="30" /> 
    <Son Name="veran_text" SonSort="2" /> 
    <Printtype Big="1" /> 
</Field> 
<Field Name="SRBE/TravelType" > 
<Position Row="0" Col="70" Len="8" /> 
    <Son Name="veran_reiseart" SonSort="3" /> 
</Field> 
<Field Name="SRBE/OperatorStreet" > 
<Position Row="1" Col="16" Len="30" /> 
    <Son Name="veran_strasse" SonSort="4" /> 
</Field> 
<Field Name="SRBE/OperatorCity" > 
<Position Row="2" Col="16" Len="30" /> 
    <Son Name="veran_ort" SonSort="5" /> 
</Field> 
<Field Name="SRBE/OperatorPhone" > 
<Position Row="3" Col="16" Len="5" /> 
    <Son Name="veran_tel" SonSort="6" /> 
</Field> 
<Field Name="SRBE/OperatorPhoneNo" > 
<Position Row="3" Col="23" Len="20" /> 
    <Son Name="veran_tel_nr" SonSort="7" /> 
</Field> 
<Field Name="SRBE/OperatorFax" > 
<Position Row="3" Col="44" Len="4" /> 
    <Son Name="veran_fax" SonSort="8" /> 
</Field> 
<Field Name="SRBE/OperatorFaxNo" > 
<Position Row="3" Col="50" Len="10" /> 
    <Son Name="veran_fax_nr" SonSort="9" /> 
</Field> 
<Field Name="SRBE/OperatorEmail" > 
<Position Row="4" Col="16" Len="6" /> 
    <Son Name="veran_email" SonSort="10" /> 
</Field> 
<Field Name="SRBE/OperatorEmailAddr" > 
<Position Row="4" Col="23" Len="34" /> 
    <Son Name="veran_email_adr" SonSort="11" /> 
</Field> 
<Field Name="SRBE/BookingNoStart" > 
<Position Row="6" Col="11" Len="13" /> 
    <Son Name="vorgangsnr_start" SonSort="12" /> 
</Field> 
<Field Name="SRBE/BookingNoOperator" > 
<Position Row="6" Col="24" Len="12" /> 
    <Son Name="vorgangsnr_veran" SonSort="13" /> 
</Field> 
<Field Name="SRBE/Headline" > 
<Position Row="6" Col="44" Len="30" /> 
    <Son Name="ueberschrift_rbe" SonSort="14" /> 
    <Printtype Big="1" /> 
</Field> 
<Field Name="SRBE/Copy" > 
<Position Row="7" Col="44" Len="36" /> 
    <Son Name="kopie" SonSort="15" /> 
</Field> 
<Field Name="SRBE/BookingDate" > 
<Position Row="8" Col="16" Len="10" /> 
    <Son Name="buchungsdatum" SonSort="16" /> 
</Field> 
<Field Name="SRBE/BookingTime" > 
<Position Row="8" Col="28" Len="5" /> 
    <Son Name="buchungsuhrzeit" SonSort="17" /> 
</Field> 
<Field Name="SRBE/InvoiceNo" > 
<Position Row="8" Col="44" Len="14" /> 
    <Son Name="rechnungsnr" SonSort="18" /> 
</Field> 
<Field Name="SRBE/Number" > 
<Position Row="8" Col="59" Len="10" /> 
    <Son Name="nummer" SonSort="19" /> 
</Field> 
<Field Name="SRBE/VestingDate" > 
<Position Row="9" Col="16" Len="10" /> 
    <Son Name="leistungsbeginn" SonSort="20" /> 
</Field> 
<Field Name="SRBE/From" > 
<Position Row="9" Col="47" Len="10" /> 
    <Son Name="vom" SonSort="21" /> 
</Field> 
<Field Name="SRBE/Time" > 
<Position Row="9" Col="59" Len="5" /> 
    <Son Name="zeit" SonSort="22" /> 
</Field> 
<Field Name="SRBE/Page" > 
<Position Row="9" Col="68" Len="5" /> 
    <Son Name="seite" SonSort="23" /> 
</Field> 
<Field Name="SRBE/IndicatorSupplement" > 
<Position Row="10" Col="2" Len="78" /> 
    <Son Name="hinweis_beiblatt" SonSort="24" /> 
    <Printtype Italic="1" /> 
    </Field> 
<Field Name="SRBE/IndicatorInsolvency" > 
<Position Row="11" Col="2" Len="78" /> 
    <Son Name="hinweis_insolvenz" SonSort="25" /> 
    <Printtype Italic="1" /> 
    </Field> 
<Field Name="SRBE/FreeFormatLine" > 
<Position Row="13" Col="2" Len="78" /> 
    <Son Name="frei_format_zeile" SonSort="26" MaxOccurs="40" /> 
</Field> 
<Field Name="SRBE/ProtectionPackage" > 
<Position Row="54" Col="2" Len="56" /> 
    <Son Name="text_schutzpaket" SonSort="27" /> 
</Field> 
<Field Name="SRBE/PrintNo" > 
<Position Row="57" Col="41" Len="2" /> 
    <Son Name="druckversuche" SonSort="28" /> 
</Field> 
<Field Name="SRBE/StaffNo" > 
<Position Row="58" Col="16" Len="4" /> 
    <Son Name="expedient" SonSort="29" /> 
</Field> 
<Field Name="SRBE/CostCenter" > 
<Position Row="58" Col="21" Len="3" /> 
    <Son Name="kostenstelle" SonSort="30" /> 
</Field> 
<Field Name="SRBE/OrderNo" > 
<Position Row="58" Col="25" Len="4" /> 
    <Son Name="auftrag" SonSort="31" /> 
</Field> 
<Field Name="SRBE/SRZAgency" > 
<Position Row="58" Col="30" Len="6" /> 
    <Son Name="rz_ag" SonSort="32" /> 
</Field> 
<Field Name="SRBE/SRZOffice" > 
<Position Row="58" Col="37" Len="3" /> 
    <Son Name="rz_bst" SonSort="33" /> 
</Field> 
<Field Name="SRBE/PhoneLabel" > 
<Position Row="60" Col="6" Len="5" /> 
    <Son Name="tel" SonSort="34" /> 
</Field> 
<Field Name="SRBE/PhoneNo" > 
<Position Row="60" Col="12" Len="20" /> 
    <Son Name="tel_nr" SonSort="35" /> 
</Field> 
<Field Name="SRBE/CustomerTitle" > 
<Position Row="61" Col="6" Len="30" /> 
    <Son Name="kundenadr_titel" SonSort="36" /> 
</Field> 
<Field Name="SRBE/CustomerName" > 
<Position Row="62" Col="6" Len="30" /> 
    <Son Name="kundenadr_name" SonSort="37" /> 
</Field> 
<Field Name="SRBE/TravelAgencyAddr_1" > 
<Position Row="62" Col="38" Len="33" /> 
    <Son Name="reisebuero_adr_1" SonSort="38" /> 
    <Printtype Tight="1" /> 
    </Field> 
<Field Name="SRBE/CustomerStreet" > 
<Position Row="63" Col="6" Len="30" /> 
    <Son Name="kundenadr_str" SonSort="39" /> 
</Field> 
<Field Name="SRBE/TravelAgencyAddr_2" > 
<Position Row="63" Col="38" Len="33" /> 
    <Son Name="reisebuero_adr_2" SonSort="40" /> 
    <Printtype Tight="1" /> 
    </Field> 
<Field Name="SRBE/CustomerAddOn" > 
<Position Row="64" Col="6" Len="30" /> 
    <Son Name="kundenadr_zusatz" SonSort="41" /> 
</Field> 
<Field Name="SRBE/TravelAgencyAddr_3" > 
<Position Row="64" Col="38" Len="33" /> 
    <Son Name="reisebuero_adr_3" SonSort="42" /> 
    <Printtype Tight="1" /> 
    </Field> 
<Field Name="SRBE/CustomerCity" > 
<Position Row="65" Col="6" Len="34" /> 
    <Son Name="kundenadr_ort" SonSort="43" /> 
</Field> 
<Field Name="SRBE/TravelAgencyAddr_4" > 
<Position Row="65" Col="38" Len="33" /> 
    <Son Name="reisebuero_adr_4" SonSort="44" /> 
    <Printtype Tight="1" /> 
    </Field> 
<Field Name="SRBE/TravelAgencyAddr_5" > 
<Position Row="66" Col="38" Len="33" /> 
    <Son Name="reisebuero_adr_5" SonSort="45" /> 
    <Printtype Tight="1" /> 
    </Field> 
    </Interface> 
    </Mask> 
</STARTMasks> 
</Repository> 

Antwort

0

Ihr Code hat

<xsl:call-template name="common"></xsl:call-template> 

    <!-- check if mask is an SRBE --> 
    <xsl:if test="$mask = 'SRBE'"> 
     <!-- iterate over all Field elements --> 
     <xsl:for-each select="$path/Field"> 
      <!-- set variable fieldName with exploded Field Name --> 
      <xsl:variable name="fieldName"> 
       <xsl:value-of select="substring-after(./@Name, '/')"></xsl:value-of> 
      </xsl:variable> 

      <!-- switch case start if maxoccurs is set or not --> 
      <xsl:choose> 
       <!-- if maxoccurs is set and greater then 1 --> 
       <xsl:when test="./Son/@MaxOccurs and ./Son/@MaxOccurs > 1"> 

        <!-- manually field sets --> 
        <xsl:if test="$fieldName = 'FreeFormatLine'"> 
         <xsl:call-template name="tablePageBreak"> 
          <xsl:with-param name="fieldName"><xsl:value-of select ="$fieldName"/></xsl:with-param> 
          <xsl:with-param name="wrapperName">Line</xsl:with-param> 
         </xsl:call-template> 
        </xsl:if> 
       </xsl:when> 

, wo die ersten call-template name="common" das xsl:stylesheet Element root erstellt und dann der andere Code erstellt offensichtlich andere Elemente außerhalb des xsl:stylesheet Elements. Im Grunde muss also der gesamte folgende Code call-template name="common" in das Template common, innerhalb <xsl:element name="xsl:stylesheet">...</xsl:element> eingegeben werden.

Verwandte Themen