Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7779027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:32:48+00:00 2026-06-01T18:32:48+00:00

I use the below xslt to transform xmls, it iterates thru the Receipt/Process nodes

  • 0

I use the below xslt to transform xmls, it iterates thru the Receipt/Process
nodes and adds type attributes to the nodes. Based on the node’s value it will be string/int/float.
That part works fine.

I also should rename the “Node” node to “Node” concatenated with its index and
add an attribute which should be the “Name” node’s value.

I may have multiple “Nodes” which I would like to convert to something like this:

first Node to where the “Cuda3DLut” is coming from the <Name>Cuda3DLut</Name>

<Node1 type="Cuda3DLut" >
<Input  type="ToolLink" role="Input" format="red,green,blue">Source</Input>
<Lut type="string">Identity</Lut>
<Output type="ToolLink" role="Output" format="red,green,blue">RESULT1</Output>
<bypass type="int">0</bypass>
<nodeRole type="string">viewing</nodeRole>
<nodeShortName type="string">LUT</nodeShortName>
</Node1>

second Node to

<Node2 type="CudaTool" >
...
</Node2>

I also would like to change the “Input” node’s value if it is “MainMedia” to “Source” but only then.

Thanks a lot.

Source XML:

<Receipt>

  <Process>
    <Node>
      <Name>Cuda3DLut</Name>
      <Input>MainMedia</Input>
      <Lut>Identity</Lut>
      <Output>RESULT1</Output>
      <bypass>0</bypass>
      <nodeRole>viewing</nodeRole>
      <nodeShortName>LUT</nodeShortName>
    </Node>
   <Node>
      <Name>CudaTool</Name>
      <Input>MainMedia</Input>
      <Lut>Identity</Lut>
      <Output>RESULT1</Output>
      <bypass>0</bypass>
      <nodeRole>viewing</nodeRole>
      <nodeShortName>LUT</nodeShortName>
    </Node>
  </Process>

  <Encode>
    <Job>
     ...
    </Job>
  </Encode>

</Receipt>

xslt: 

<?xml version="1.0"?>
<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:template match="/">
      <cut>
        <xsl:apply-templates/>        
    </cut>
 </xsl:template>


  <xsl:template match="Process">

      <xsl:for-each select="Node/*">

        <xsl:choose>

            <xsl:when test="name() = 'Input'">

              <xsl:copy>
                <xsl:attribute name="type">ToolLink</xsl:attribute>
                <xsl:attribute name="role">Input</xsl:attribute>
                <xsl:attribute name="format">red,green,blue</xsl:attribute>
                <xsl:apply-templates select="@*|node()" />
              </xsl:copy>              

            </xsl:when>

            <xsl:when test="name() = 'Output'">
              <xsl:copy>
                <xsl:attribute name="type">ToolLink</xsl:attribute>
                <xsl:attribute name="role">Output</xsl:attribute>
                <xsl:attribute name="format">red,green,blue</xsl:attribute>
                <xsl:apply-templates select="@*|node()" />
              </xsl:copy>              

            </xsl:when>

          <xsl:otherwise>

            <!-- Add type attribute to the node based on its value -->
            <xsl:choose>
            <xsl:when test="number(.) = .">
              <xsl:choose>
                <xsl:when test="contains(., '.')">
                <xsl:copy>
                  <xsl:attribute name="type">float</xsl:attribute>
                  <xsl:apply-templates select="@*|node()" />
                </xsl:copy>
              </xsl:when>
              <xsl:otherwise>
                <xsl:copy>
                  <xsl:attribute name="type">int</xsl:attribute>
                  <xsl:apply-templates select="@*|node()" />
                </xsl:copy>
              </xsl:otherwise>
             </xsl:choose>                                      
            </xsl:when>
            <xsl:otherwise>
              <xsl:copy>
                <xsl:attribute name="type">string</xsl:attribute>
                <xsl:apply-templates select="@*|node()" />
              </xsl:copy>            
            </xsl:otherwise>            
          </xsl:choose>

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

      </xsl:for-each>

  </xsl:template>

  <xsl:template match="Encode">    
  </xsl:template>

</xsl:stylesheet>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T18:32:50+00:00Added an answer on June 1, 2026 at 6:32 pm

    This transformation:

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
     <xsl:strip-space elements="*"/>
    
     <xsl:template match="Node">
         <xsl:element name="Node{position()}">
           <xsl:attribute name="type">
             <xsl:value-of select="Name"/>
           </xsl:attribute>
           <xsl:apply-templates select="*[not(self::Name)]"/>
         </xsl:element>
     </xsl:template>
    
     <xsl:template match="Node/*" priority="-1">
      <xsl:copy>
        <xsl:attribute name="type">string</xsl:attribute>
        <xsl:value-of select="."/>
      </xsl:copy>
     </xsl:template>
    
     <xsl:template match="Node/Input">
       <Input  type="ToolLink" role="Input" format="red,green,blue">Source</Input>
     </xsl:template>
    
     <xsl:template match="Output">
       <Output  type="ToolLink" role="Output" format="red,green,blue">
         <xsl:value-of select="."/>
       </Output>
     </xsl:template>
    
     <xsl:template match="bypass">
      <bypass type="int"><xsl:value-of select="."/></bypass>
     </xsl:template>
    </xsl:stylesheet>
    

    when applied on the provided XML document:

    <Receipt>
        <Process>
            <Node>
                <Name>Cuda3DLut</Name>
                <Input>MainMedia</Input>
                <Lut>Identity</Lut>
                <Output>RESULT1</Output>
                <bypass>0</bypass>
                <nodeRole>viewing</nodeRole>
                <nodeShortName>LUT</nodeShortName>
            </Node>
            <Node>
                <Name>CudaTool</Name>
                <Input>MainMedia</Input>
                <Lut>Identity</Lut>
                <Output>RESULT1</Output>
                <bypass>0</bypass>
                <nodeRole>viewing</nodeRole>
                <nodeShortName>LUT</nodeShortName>
            </Node>
        </Process>
        <Encode>
            <Job>      ...     </Job>
        </Encode>
    </Receipt>
    

    produces the wanted, correct result:

    <Node1 type="Cuda3DLut">
       <Input type="ToolLink" role="Input" format="red,green,blue">Source</Input>
       <Lut type="string">Identity</Lut>
       <Output type="ToolLink" role="Output" format="red,green,blue">RESULT1</Output>
       <bypass type="int">0</bypass>
       <nodeRole type="string">viewing</nodeRole>
       <nodeShortName type="string">LUT</nodeShortName>
    </Node1>
    <Node2 type="CudaTool">
       <Input type="ToolLink" role="Input" format="red,green,blue">Source</Input>
       <Lut type="string">Identity</Lut>
       <Output type="ToolLink" role="Output" format="red,green,blue">RESULT1</Output>
       <bypass type="int">0</bypass>
       <nodeRole type="string">viewing</nodeRole>
       <nodeShortName type="string">LUT</nodeShortName>
    </Node2> 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I tried to use a XSLT transformation (below) to a RSS with this type
I am making use of XSLT 2.0 to find the matching substring based on
When I use the xpath select as per the xslt below <?xml version=1.0 encoding=UTF-8?>
During transformation, who I can combine one node into another. for example, when Attributes/Attribute/Type=ComplexAttr
I use below code to post an url to facebook page as a admin
I use below code to update listview. setListAdapter(MyAdapter); MyAdapter.notifyDataSetChanged(); getListView().setEmptyView(empty); But each time update,
i use below code - Just try again. - to prevent deadlock. it seems
I use below code to get photo's path and id: String[] projection = {MediaStore.Images.Media._ID,
I use below call to play music: vv = (VideoView)findViewById(R.id.screen_audio); Uri music = Uri.parse(path);
I use below code to show folder list in AlertDialog: ListDialog = new AlertDialog.Builder(MyActivity.this);

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.