0

I am new to stackverflow and hoping I will get right direction for my current issue. I have XSD input and i am writing xslt for this input and was trying to call one element into other one's and for some reason it is not working.

following is my XSD input,

  <?xml version="1.0" encoding="UTF-8"?>
 <xsd:schema xmlns:ts="http://schemas.capeclear.com/2003/02/TextSchema"
 xmlns:xsd="http://www.w3.org/2001/XMLSchema" ts:eofStrip="&amp;#10;"
 targetNamespace="http://textschema/ABC_Indirect_Deductions_WIP/MediaOut.xsd"
 xmlns:tns="http://textschema/ABC_Indirect_Deductions_WIP/MediaOut.xsd"
 ts:numberFormat="#,###.#" ts:rootElement="tns:File">

<xsd:element name="File">
    <xsd:complexType>
        <xsd:sequence>
        
            <xsd:element name="Vendor_Data" ts:align="left" minOccurs="0"
                maxOccurs="1" ts:endTag="\n" ts:startTag="1">
                <xsd:complexType>
                    <xsd:sequence>
        
                        <xsd:element name="Vendor_ID" type="xsd:string"
                            ts:fixedLength="5" />
                        <xsd:element name="Assignment_ID" type="xsd:string"
                            ts:fixedLength="6" />
                        <xsd:element name="Begin_Date" type="xsd:string"
                            ts:fixedLength="8" />
                      <xsd:element name="Assigned_Date_Time"type="xsd:string"
                            ts:fixedLength="20" />
                        <xsd:element name="Sender_Code" type="xsd:string"
                            ts:fixedLength="2" />
                        <xsd:element name="Level_Flag"
                            type="xsd:string" ts:fixedLength="1" />
        <xsd:element name="Filler1" type="xsd:string" ts:fixedLength="76"/>
                    </xsd:sequence>
                </xsd:complexType>
            </xsd:element>
                            
  <xsd:element name="Applicant_Data" ts:align="left" minOccurs="0" maxOccurs="unbounded" 
  ts:endTag="\n" ts:startTag="2">
                <xsd:complexType>
                    <xsd:sequence>
                        <xsd:element name="Class_ID" type="xsd:string"
                            ts:fixedLength="6" minOccurs="0" />
                        <xsd:element name="Applicant_ID" type="xsd:string"
                            ts:fixedLength="9" minOccurs="0" />
                        <xsd:element name="Personal_Number" type="xsd:string"
                            ts:fixedLength="15" minOccurs="0" />
                        <xsd:element name="Effective_Date" type="xsd:string"
                            ts:fixedLength="8" minOccurs="0" ts:align="left" />
                        <xsd:element name="Transfer_Type" type="xsd:string"
                            ts:fixedLength="3" minOccurs="0" />
                        <xsd:element name="Deduction_Percent" type="xsd:integer"
                            ts:fixedLength="5" minOccurs="0" />
                        <xsd:element name="End_Date" type="xsd:string"
                            ts:fixedLength="8" minOccurs="0" />
                        <xsd:element name="Availability_Date" type="xsd:string"
                            ts:fixedLength="8" minOccurs="0" />
                        <xsd:element name="Participant_Name" type="xsd:string"
                            ts:fixedLength="30" minOccurs="0" />
                        <xsd:element name="Allocation10" type="xsd:string"
                            ts:fixedLength="2" minOccurs="0" ts:align="left"/>
                    </xsd:sequence>
                </xsd:complexType>
            </xsd:element>
                                  <xsd:element name="Pay_Data" ts:align="left" minOccurs="0"
                maxOccurs="unbounded" ts:endTag="\n" ts:startTag="091341">  
                <xsd:complexType>
            <xsd:sequence>
                        
        <xsd:element name="Payrate_Rate" type="xsd:string" ts:fixedLength="7" minOccurs="0" />
         <xsd:element name="Pay_Date" type="xsd:string" ts:fixedLength="6" minOccurs="0" />
         <xsd:element name="Payments" type="xsd:string" ts:fixedLength="5" minOccurs="0" />
         <xsd:element name="Payment_Amount" type="xsd:string" ts:fixedLength="11" minOccurs="0" />
         <xsd:element name="Member_ID" type="xsd:string" ts:fixedLength="13" minOccurs="0" />
         <xsd:element name="Frequency" type="xsd:string" ts:fixedLength="1" minOccurs="0" />
         <xsd:element name="Veteran_Name" type="xsd:string" ts:fixedLength="30" minOccurs="0" />
         <xsd:element name="Country" type="xsd:string" ts:fixedLength="10" minOccurs="0" />
         
              </xsd:sequence>
            </xsd:complexType>
            </xsd:element>
            </xsd:sequence>
      </xsd:complexType>
</xsd:element>

</xsd:schema>

And following is my xslt, i am trying to call element begin date from vendor data element into other two element called Applicant_Data and Pay_data but seems it is not working as needed and hence reaching out for any help or assistance on this.

Following is the XSLT I have written for this and let me know for any changes if needed on this to have begin date called into other element named Applicant_Data and Pay_data.

   <?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" indent="yes" omit-xml-declaration="yes" />

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

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

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

<xsl:template name="vendor_tokenize">
    
        <xsl:element name="Start_Date">
            <xsl:variable name="MM"
                select="substring(Begin_Date,5,2)" />

            <xsl:variable name="DD"
                select="substring(Begin_Date,7,2)" />

            <xsl:variable name="YYYY"
                select="substring(Begin_Date,1,4)" />
    <xsl:value-of select="normalize-space(concat($YYYY,'-',$MM,'-',$DD))" />
        </xsl:element>
    
</xsl:template>

<xsl:template name="applicant_tokenize">
    <xsl:element name="Applicant">
        <xsl:element name="Applicant_ID">
            <xsl:value-of select="normalize-space(Applicant_ID)" />
        </xsl:element>
        <xsl:element name="Personal_Number">
            <xsl:value-of select="normalize-space(Personal_Number)" />
        </xsl:element>
        <xsl:element name="Event_Date">
            <xsl:variable name="MM"
                select="substring(Effective_Date,5,2)" />

            <xsl:variable name="DD"
                select="substring(Effective_Date,7,2)" />

            <xsl:variable name="YYYY"
                select="substring(Effective_Date,1,4)" />
    <xsl:value-of select="normalize-space(concat($YYYY,'-',$MM,'-',$DD))" />
        </xsl:element>              
    </xsl:element>
</xsl:template>

<xsl:template name="pay_tokenize">
    <xsl:element name="Pay_Date">
        
        <xsl:element name="Pay_Date">
        <xsl:variable name="MM" select="substring(Pay_Date,3,2)" />

        <xsl:variable name="DD" select="substring(Pay_Date,5,2)" />

        <xsl:variable name="YY" select="substring(Pay_Date,1,2)" />

<xsl:value-of select="normalize-space(concat('20',$YY,'-',$MM,'-',$DD))" />
        </xsl:element>
        
    </xsl:element>
</xsl:template>

</xsl:stylesheet>

INPUT DATA FILE

0135091341202104032021-04-02.00.04.31 02TGT
3012 3245678 802275 20210414EEE0162021021520210215ALEX, RONALD FG 091341 20210414 277 16677 802275 2 ALEX, RONALD USA

Let me know for any additional information if needed on this.

  • Welcome to Stack Overflow. "i am writing xslt for this input": What is the wanted output? Why are you doing this in the first place? What does xsd2code have to do with this? – mzjn Apr 15 '21 at 12:39
  • Hi mzjn, I actually have existing interface built where I am getting input in xsd and elements of Applicant_Data and Pay_Data are interfaced. Date elements Effective_Date and Pay_Date are being sent currently, but instead of these two dates, Begin_Date has to be sent. So since Applicant_Data and Pay_Data are linked to interface, i was trying to just call Begin Date from vendor tokenize into both applicant and pay tokenize which can be called into integration, let me know if this gives clear understanding, all I want is Begin_Date element from first template to be called into other two. –  Apr 15 '21 at 13:15
  • To clarify the question, please edit it. Is the schema really the input? This is confusing. – mzjn Apr 15 '21 at 13:17
  • mzjn, apologies for any confusion. edited with input data and currently date is being sent from second and third lines. But actually date from first line is supposed to send. so trying to call element name begin date from first element into other two elements which will fix the issue. Let me know if this makes clear, i know this is little confusing but all i want is to call element from first element into other two elements. let me know if you need any additional information on this. –  Apr 15 '21 at 16:54
  • 2
    Please edit your question again and add (1) an example of the **XML input** (not schema or raw data) and (2) the expected output of transforming the example input. – michael.hor257k Apr 15 '21 at 16:58
  • Michael, I am getting XSD input which is provided above and I am using XSLT to transform into XML. I have provided XSLT above that I have written which is transforming into XML. Point where I am struggling is, I wanted to call element Begin_Date into other elements and replace it with effective date and pay date from two different elements. let me know if this gives clear understanding...! –  Apr 15 '21 at 17:45
  • An XSD is NOT an input (unless you are modifying the schema). It contains no actual data. It only describes what the XML input should look like. Show us an actual XML document that contains example data and also the expected output. – michael.hor257k Apr 15 '21 at 17:53

0 Answers0