Problem with XSL transformation copying data from xml file2019 Community Moderator ElectionXSLT - Adding Elements dynamicallyHow to enable XSLT scripting in C# ..?XML and XSL connectionxsl:variable as xpath value for other xsl tagHow to concatenate two or more xml files using xslt and maintain the order?Copy data from one XML doc to another using XSLTHow to process all data from multiple XML files after merging using XSLXSLT to map elements copied fileget another xml value located in another path using xsltProblem with copying data from an xml file to another xml file using xslt

Is this Paypal Github SDK reference really a dangerous site?

What is the generally accepted pronunciation of “topoi”?

Why is there an extra space when I type "ls" in the Desktop directory?

Has a sovereign Communist government ever run, and conceded loss, on a fair election?

How do electrons receive energy when a body is heated?

What is this diamond of every day?

Is it safe to abruptly remove Arduino power?

Is it possible to avoid unpacking when merging Association?

What is better: yes / no radio, or simple checkbox?

Why couldn't the separatists legally leave the Republic?

Specifying a starting column with colortbl package and xcolor

How to resolve: Reviewer #1 says remove section X vs. Reviewer #2 says expand section X

Why restrict private health insurance?

Does an unused member variable take up memory?

Which situations would cause a company to ground or recall a aircraft series?

How does Ehrenfest's theorem apply to the quantum harmonic oscillator?

How do spaceships determine each other's mass in space?

What sort of fish is this

Confusion about Complex Continued Fraction

Possible to detect presence of nuclear bomb?

School performs periodic password audits. Is my password compromised?

Vocabulary for giving just numbers, not a full answer

Plausibility of Mushroom Buildings

Making a kiddush for a girl that has hard time finding shidduch



Problem with XSL transformation copying data from xml file



2019 Community Moderator ElectionXSLT - Adding Elements dynamicallyHow to enable XSLT scripting in C# ..?XML and XSL connectionxsl:variable as xpath value for other xsl tagHow to concatenate two or more xml files using xslt and maintain the order?Copy data from one XML doc to another using XSLTHow to process all data from multiple XML files after merging using XSLXSLT to map elements copied fileget another xml value located in another path using xsltProblem with copying data from an xml file to another xml file using xslt










0















I am trying to copy data from file2 to file1 using xsl transformation. I am able to copy the data, but my xsd validation fails on the resulting xml file. Here is my code:



file1.xml:



<Org>
<Security xmlns:saxon="http://saxon.sf.net" />
</Org>
<Org>
<Security xmlns:saxon="http://saxon.sf.net">
<Access Privileges>
<Access Rules>Rule1</Access Rules>
</Access Privileges>
</Security>
</Org>


file2.xml:



<AccessProfile>
<Policy description="SecurityProfile">Policy1</Policy>
<PolicyValue description="SecurityProfile">Value1</PolicyValue>
</AccessProfile>


result.xml:



 <Org>
<Security>
<Access>
<AccessProfile>
<Policy>Policy1</Policy>
<PolicyValue>Value1</PolicyValue>
</AccessProfile>
</Access>
</Security>
<Org>
</Org>
<Security>
<Access>
<AccessProfile>
<Policy>Policy1</Policy>
<PolicyValue>Value1</PolicyValue>
</AccessProfile>
</Access>
</Security>
</Org>


Desired output:



 <Org>
<Security xmlns:saxon="http://saxon.sf.net" newAttr="Attr1">
<Access>
<AccessProfile description="SecurityProfile">
<Policy description="SecurityProfile">Policy1</Policy>
<PolicyValue description="SecurityProfile" vocabulary="simple">Value1</PolicyValue>
</AccessProfile>
</Access>
</Security>
</Org>
<Org>
<Security xmlns:saxon="http://saxon.sf.net" newAttr="Attr1">
<Access Privileges>
<Access Rules>Rule1</Access Rules>
</Access Privileges>
<Access>
<AccessProfile description="SecurityProfile">
<Policy description="SecurityProfile">Policy1</Policy>
<PolicyValue description="SecurityProfile" vocabulary="simple">Value1</PolicyValue>
</AccessProfile>
</Access>
</Security>
</Org>


Here is the code from my xsl file:



 <xsl:template match="*[local-name()='Org']/*[local-name()='Security']">
<xsl:variable name="securityDesc" select="document($lookup)/@sam:description" />
<xsl:copy>
<xsl:element name="Access">
<xsl:attribute name="description"><xsl:value-of select="$securityDesc" /></xsl:attribute>
<xsl:for-each select="document($lookup)/AccessProfile">
<xsl:copy>
<xsl:attribute name="description"><xsl:value-of
select="$securityDesc" /></xsl:attribute>

<xsl:for-each select="document($lookup)/AccessProfile/*">
<xsl:variable name="vocabulary" select="document($lookup)/AccessProfileValue/@profileVal" />
<xsl:element name="name(.)">
<xsl:attribute name="description"><xsl:value-of select="$securityDesc" /></xsl:attribute>

<xsl:if test="*[name(.)='PolicyValue']">
<xsl:attribute name="vocabulary"><xsl:value-of select="$vocabulary" /></xsl:attribute>
</xsl:if>

<xsl:value-of select="." />
</xsl:element>
</xsl:for-each>
</xsl:copy>
</xsl:for-each>
</xsl:element>
</xsl:copy>
</xsl:template>


I am trying to copy a node AccessProfile with elements into Security node under an element called Access. When I copy it, it will remove any other child nodes under Security as shown in the result.xml for the second Security element. I need to keep the data intact. Also I need to add attribute on one of the copied elements for it to pass validation. I am trying to add an attribute to one of the added node elements and not able to do it. Also I need to add additional attributes to the Security node for the validation. Thanks for the help.










share|improve this question


























    0















    I am trying to copy data from file2 to file1 using xsl transformation. I am able to copy the data, but my xsd validation fails on the resulting xml file. Here is my code:



    file1.xml:



    <Org>
    <Security xmlns:saxon="http://saxon.sf.net" />
    </Org>
    <Org>
    <Security xmlns:saxon="http://saxon.sf.net">
    <Access Privileges>
    <Access Rules>Rule1</Access Rules>
    </Access Privileges>
    </Security>
    </Org>


    file2.xml:



    <AccessProfile>
    <Policy description="SecurityProfile">Policy1</Policy>
    <PolicyValue description="SecurityProfile">Value1</PolicyValue>
    </AccessProfile>


    result.xml:



     <Org>
    <Security>
    <Access>
    <AccessProfile>
    <Policy>Policy1</Policy>
    <PolicyValue>Value1</PolicyValue>
    </AccessProfile>
    </Access>
    </Security>
    <Org>
    </Org>
    <Security>
    <Access>
    <AccessProfile>
    <Policy>Policy1</Policy>
    <PolicyValue>Value1</PolicyValue>
    </AccessProfile>
    </Access>
    </Security>
    </Org>


    Desired output:



     <Org>
    <Security xmlns:saxon="http://saxon.sf.net" newAttr="Attr1">
    <Access>
    <AccessProfile description="SecurityProfile">
    <Policy description="SecurityProfile">Policy1</Policy>
    <PolicyValue description="SecurityProfile" vocabulary="simple">Value1</PolicyValue>
    </AccessProfile>
    </Access>
    </Security>
    </Org>
    <Org>
    <Security xmlns:saxon="http://saxon.sf.net" newAttr="Attr1">
    <Access Privileges>
    <Access Rules>Rule1</Access Rules>
    </Access Privileges>
    <Access>
    <AccessProfile description="SecurityProfile">
    <Policy description="SecurityProfile">Policy1</Policy>
    <PolicyValue description="SecurityProfile" vocabulary="simple">Value1</PolicyValue>
    </AccessProfile>
    </Access>
    </Security>
    </Org>


    Here is the code from my xsl file:



     <xsl:template match="*[local-name()='Org']/*[local-name()='Security']">
    <xsl:variable name="securityDesc" select="document($lookup)/@sam:description" />
    <xsl:copy>
    <xsl:element name="Access">
    <xsl:attribute name="description"><xsl:value-of select="$securityDesc" /></xsl:attribute>
    <xsl:for-each select="document($lookup)/AccessProfile">
    <xsl:copy>
    <xsl:attribute name="description"><xsl:value-of
    select="$securityDesc" /></xsl:attribute>

    <xsl:for-each select="document($lookup)/AccessProfile/*">
    <xsl:variable name="vocabulary" select="document($lookup)/AccessProfileValue/@profileVal" />
    <xsl:element name="name(.)">
    <xsl:attribute name="description"><xsl:value-of select="$securityDesc" /></xsl:attribute>

    <xsl:if test="*[name(.)='PolicyValue']">
    <xsl:attribute name="vocabulary"><xsl:value-of select="$vocabulary" /></xsl:attribute>
    </xsl:if>

    <xsl:value-of select="." />
    </xsl:element>
    </xsl:for-each>
    </xsl:copy>
    </xsl:for-each>
    </xsl:element>
    </xsl:copy>
    </xsl:template>


    I am trying to copy a node AccessProfile with elements into Security node under an element called Access. When I copy it, it will remove any other child nodes under Security as shown in the result.xml for the second Security element. I need to keep the data intact. Also I need to add attribute on one of the copied elements for it to pass validation. I am trying to add an attribute to one of the added node elements and not able to do it. Also I need to add additional attributes to the Security node for the validation. Thanks for the help.










    share|improve this question
























      0












      0








      0








      I am trying to copy data from file2 to file1 using xsl transformation. I am able to copy the data, but my xsd validation fails on the resulting xml file. Here is my code:



      file1.xml:



      <Org>
      <Security xmlns:saxon="http://saxon.sf.net" />
      </Org>
      <Org>
      <Security xmlns:saxon="http://saxon.sf.net">
      <Access Privileges>
      <Access Rules>Rule1</Access Rules>
      </Access Privileges>
      </Security>
      </Org>


      file2.xml:



      <AccessProfile>
      <Policy description="SecurityProfile">Policy1</Policy>
      <PolicyValue description="SecurityProfile">Value1</PolicyValue>
      </AccessProfile>


      result.xml:



       <Org>
      <Security>
      <Access>
      <AccessProfile>
      <Policy>Policy1</Policy>
      <PolicyValue>Value1</PolicyValue>
      </AccessProfile>
      </Access>
      </Security>
      <Org>
      </Org>
      <Security>
      <Access>
      <AccessProfile>
      <Policy>Policy1</Policy>
      <PolicyValue>Value1</PolicyValue>
      </AccessProfile>
      </Access>
      </Security>
      </Org>


      Desired output:



       <Org>
      <Security xmlns:saxon="http://saxon.sf.net" newAttr="Attr1">
      <Access>
      <AccessProfile description="SecurityProfile">
      <Policy description="SecurityProfile">Policy1</Policy>
      <PolicyValue description="SecurityProfile" vocabulary="simple">Value1</PolicyValue>
      </AccessProfile>
      </Access>
      </Security>
      </Org>
      <Org>
      <Security xmlns:saxon="http://saxon.sf.net" newAttr="Attr1">
      <Access Privileges>
      <Access Rules>Rule1</Access Rules>
      </Access Privileges>
      <Access>
      <AccessProfile description="SecurityProfile">
      <Policy description="SecurityProfile">Policy1</Policy>
      <PolicyValue description="SecurityProfile" vocabulary="simple">Value1</PolicyValue>
      </AccessProfile>
      </Access>
      </Security>
      </Org>


      Here is the code from my xsl file:



       <xsl:template match="*[local-name()='Org']/*[local-name()='Security']">
      <xsl:variable name="securityDesc" select="document($lookup)/@sam:description" />
      <xsl:copy>
      <xsl:element name="Access">
      <xsl:attribute name="description"><xsl:value-of select="$securityDesc" /></xsl:attribute>
      <xsl:for-each select="document($lookup)/AccessProfile">
      <xsl:copy>
      <xsl:attribute name="description"><xsl:value-of
      select="$securityDesc" /></xsl:attribute>

      <xsl:for-each select="document($lookup)/AccessProfile/*">
      <xsl:variable name="vocabulary" select="document($lookup)/AccessProfileValue/@profileVal" />
      <xsl:element name="name(.)">
      <xsl:attribute name="description"><xsl:value-of select="$securityDesc" /></xsl:attribute>

      <xsl:if test="*[name(.)='PolicyValue']">
      <xsl:attribute name="vocabulary"><xsl:value-of select="$vocabulary" /></xsl:attribute>
      </xsl:if>

      <xsl:value-of select="." />
      </xsl:element>
      </xsl:for-each>
      </xsl:copy>
      </xsl:for-each>
      </xsl:element>
      </xsl:copy>
      </xsl:template>


      I am trying to copy a node AccessProfile with elements into Security node under an element called Access. When I copy it, it will remove any other child nodes under Security as shown in the result.xml for the second Security element. I need to keep the data intact. Also I need to add attribute on one of the copied elements for it to pass validation. I am trying to add an attribute to one of the added node elements and not able to do it. Also I need to add additional attributes to the Security node for the validation. Thanks for the help.










      share|improve this question














      I am trying to copy data from file2 to file1 using xsl transformation. I am able to copy the data, but my xsd validation fails on the resulting xml file. Here is my code:



      file1.xml:



      <Org>
      <Security xmlns:saxon="http://saxon.sf.net" />
      </Org>
      <Org>
      <Security xmlns:saxon="http://saxon.sf.net">
      <Access Privileges>
      <Access Rules>Rule1</Access Rules>
      </Access Privileges>
      </Security>
      </Org>


      file2.xml:



      <AccessProfile>
      <Policy description="SecurityProfile">Policy1</Policy>
      <PolicyValue description="SecurityProfile">Value1</PolicyValue>
      </AccessProfile>


      result.xml:



       <Org>
      <Security>
      <Access>
      <AccessProfile>
      <Policy>Policy1</Policy>
      <PolicyValue>Value1</PolicyValue>
      </AccessProfile>
      </Access>
      </Security>
      <Org>
      </Org>
      <Security>
      <Access>
      <AccessProfile>
      <Policy>Policy1</Policy>
      <PolicyValue>Value1</PolicyValue>
      </AccessProfile>
      </Access>
      </Security>
      </Org>


      Desired output:



       <Org>
      <Security xmlns:saxon="http://saxon.sf.net" newAttr="Attr1">
      <Access>
      <AccessProfile description="SecurityProfile">
      <Policy description="SecurityProfile">Policy1</Policy>
      <PolicyValue description="SecurityProfile" vocabulary="simple">Value1</PolicyValue>
      </AccessProfile>
      </Access>
      </Security>
      </Org>
      <Org>
      <Security xmlns:saxon="http://saxon.sf.net" newAttr="Attr1">
      <Access Privileges>
      <Access Rules>Rule1</Access Rules>
      </Access Privileges>
      <Access>
      <AccessProfile description="SecurityProfile">
      <Policy description="SecurityProfile">Policy1</Policy>
      <PolicyValue description="SecurityProfile" vocabulary="simple">Value1</PolicyValue>
      </AccessProfile>
      </Access>
      </Security>
      </Org>


      Here is the code from my xsl file:



       <xsl:template match="*[local-name()='Org']/*[local-name()='Security']">
      <xsl:variable name="securityDesc" select="document($lookup)/@sam:description" />
      <xsl:copy>
      <xsl:element name="Access">
      <xsl:attribute name="description"><xsl:value-of select="$securityDesc" /></xsl:attribute>
      <xsl:for-each select="document($lookup)/AccessProfile">
      <xsl:copy>
      <xsl:attribute name="description"><xsl:value-of
      select="$securityDesc" /></xsl:attribute>

      <xsl:for-each select="document($lookup)/AccessProfile/*">
      <xsl:variable name="vocabulary" select="document($lookup)/AccessProfileValue/@profileVal" />
      <xsl:element name="name(.)">
      <xsl:attribute name="description"><xsl:value-of select="$securityDesc" /></xsl:attribute>

      <xsl:if test="*[name(.)='PolicyValue']">
      <xsl:attribute name="vocabulary"><xsl:value-of select="$vocabulary" /></xsl:attribute>
      </xsl:if>

      <xsl:value-of select="." />
      </xsl:element>
      </xsl:for-each>
      </xsl:copy>
      </xsl:for-each>
      </xsl:element>
      </xsl:copy>
      </xsl:template>


      I am trying to copy a node AccessProfile with elements into Security node under an element called Access. When I copy it, it will remove any other child nodes under Security as shown in the result.xml for the second Security element. I need to keep the data intact. Also I need to add attribute on one of the copied elements for it to pass validation. I am trying to add an attribute to one of the added node elements and not able to do it. Also I need to add additional attributes to the Security node for the validation. Thanks for the help.







      xml xslt






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 6 at 14:29









      iranichaiiranichai

      6829




      6829






















          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55025470%2fproblem-with-xsl-transformation-copying-data-from-xml-file%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55025470%2fproblem-with-xsl-transformation-copying-data-from-xml-file%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          AWS Lex not identifying response if by a variable The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experienceEnforcing custom enumeration in AWS LEX for slot valuesHow to give response based on user response in Amazon Lex?Intercepting AWS Lambda Response to a AWS Lex QueryLex chat bot error: Reached second execution of fulfillment lambda on the same utteranceamazon lex showing invalid responseLambda response send back to Lex slot?Response card in Amazon lexAmazon Lex - Lambda response return HTML to botHow can I solve 424 (Failed Dependency) (python) obtained from Amazon lex?

          Алба-Юлія

          Захаров Федір Захарович