logo
down
shadow

Update nodes via merge without changing node order?


Update nodes via merge without changing node order?

By : Sebastian
Date : November 17 2020, 11:55 AM
I hope this helps . If you only want to change the description nodes in document A, then to preserve the order, you should have a template in your XSLT that matches the description node, rather than its parent:
code :
 <xsl:template match="description">
 <xsl:variable name="name" select="preceding-sibling::name[1]" />
 <xsl:variable name="lookup" select="$desc//node[@name = $name]" />
    <xsl:choose>
        <xsl:when test="$lookup">
            <xsl:copy-of select="$lookup/description" />
        </xsl:when>
        <xsl:otherwise>
            <xsl:call-template name="identity" />
        </xsl:otherwise>
    </xsl:choose> 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="xml" indent="yes" />

    <xsl:variable name="desc" select="document('doc.out.xml')" />

    <xsl:template match="@*|node()" name="identity">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()" />
        </xsl:copy>
    </xsl:template>

    <xsl:template match="description">
        <xsl:variable name="name" select="preceding-sibling::name[1]" />
        <xsl:variable name="lookup" select="$desc//node[@name = $name]" />
        <xsl:choose>
            <xsl:when test="$lookup">
                <xsl:copy-of select="$lookup/description" />
            </xsl:when>
            <xsl:otherwise>
                <xsl:call-template name="identity" />
            </xsl:otherwise>
        </xsl:choose> 
    </xsl:template>
</xsl:stylesheet>


Share : facebook icon twitter icon
How do I merge two nodes into a single node using igraph

How do I merge two nodes into a single node using igraph


By : tik tik
Date : March 29 2020, 07:55 AM
wish help you to fix your issue contract.vertices is indeed the right function to try, but its API is a bit complicated since it is designed to be able to merge not only a single pair of nodes but also several pairs in a single pass. (It can also permute vertices). To this end, it requires a mapping from the old vertex IDs to the new ones.
In case you are unfamiliar with vertex IDs: igraph identifies each vertex of the graph with an integer in the range 1 to N where N is the number of vertices. The mapping that contract.vertices requires must be a list of length N where the i-th element of the list contains the new ID of the node corresponding to ID i before merging.
code :
c(1,2,3,4,5,6,7,8,9,10)
c(1,2,3,4,5,6,4,8,9,10)
c(1,2,3,4,5,6,4,7,8,9)
list("Number of Pages"="sum", "first")
Merge nodes of the same kind to a single node

Merge nodes of the same kind to a single node


By : mcabrera
Date : March 29 2020, 07:55 AM
I wish this help you I'm trying to merge 2 Nodes of the same kind into a single Node , This might help you
code :
           XmlDocument myDocument = new XmlDocument();
           myDocument.Load(XMLFile);
           var NodeToadd = myDocument.ChildNodes.OfType<XmlElement>().Where(nodeVariant => nodeVariant.Name == "Clubs").SelectMany(o => o.ChildNodes.OfType<XmlElement>()).ToList();
           var nodeToDelete = myDocument.ChildNodes.OfType<XmlElement>().Where(nodeVariant => nodeVariant.Name == "Clubs");
           foreach (var m in nodeToDelete)
           {
               myDocument.RemoveChild(m);
           }
             XmlNode newNode = myDocument.CreateElement("Clubs");
            foreach(var m in NodeToadd)
            {
            newNode.AppendChild(m);
            }
            myDocument.AppendChild(newNode);
            myDocument.Save(XMLFile);
Merge all values of a node's child nodes

Merge all values of a node's child nodes


By : Fluxifys
Date : March 29 2020, 07:55 AM
around this issue I'm completely new to XSLT. In a large text corpus, I should merge all values of a node's child nodes: , Re your Update 2
The given input:
code :
<p class="s3">
   <span class="s4">
      <span>Read</span>
   </span>
   <span class="s4">
      <span> </span>
   </span>
   <span class="s4">
      <span>the</span>
   </span>
   <span class="s4">
      <span> information </span>
   </span>
   <span class="s4">
      <span>sheet</span>
   </span>
   <span class="s4">
      <span> </span>
   </span>
   <span class="s4">
      <span>carefully</span>
   </span>
</p>
<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"/>

<!-- identity transform -->
<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="span[not(@class)]">
    <new-span>
        <xsl:apply-templates select="@*|node()"/>
    </new-span>
</xsl:template>

</xsl:stylesheet>
<p class="s3">
   <span class="s4">
      <new-span>Read</new-span>
   </span>
   <span class="s4">
      <new-span> </new-span>
   </span>
   <span class="s4">
      <new-span>the</new-span>
   </span>
   <span class="s4">
      <new-span> information </new-span>
   </span>
   <span class="s4">
      <new-span>sheet</new-span>
   </span>
   <span class="s4">
      <new-span> </new-span>
   </span>
   <span class="s4">
      <new-span>carefully</new-span>
   </span>
</p>
<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:strip-space elements="*"/>
<xsl:preserve-space elements="new-span"/>

<!-- identity transform -->
<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="p">
    <xsl:copy>
        <xsl:value-of select='.'/>
    </xsl:copy>
</xsl:template>

</xsl:stylesheet>
<?xml version="1.0" encoding="UTF-8"?>
<p>Read the information sheet carefully</p>
Merge XML nodes into one comma separated node

Merge XML nodes into one comma separated node


By : s.toff
Date : March 29 2020, 07:55 AM
I wish this helpful for you As you didn't specify the XSLT version, I used 2.0, which is more powerful and better suited for such a task.
Your script should contain:
code :
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output indent="yes"/>

  <xsl:template match="case_material">
    <xsl:copy>
      <xsl:apply-templates select="*[name() != 'option']|@*"/>
      <xsl:for-each-group select="option/*" group-by="name()">
        <xsl:if test="current-grouping-key() != 'slug_value'">
         <xsl:element name="{current-grouping-key()}">
           <xsl:value-of select="current-group()" separator=","/>
         </xsl:element>
        </xsl:if>
      </xsl:for-each-group>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="node()|@*">
    <xsl:copy><xsl:apply-templates select="node()|@*"/></xsl:copy>
  </xsl:template>
</xsl:stylesheet>
How to merge the repeated nodes into the one node?

How to merge the repeated nodes into the one node?


By : xiaohou
Date : March 29 2020, 07:55 AM
wish helps you Following up my comment, and with further investigations I managed to reduce you graph. It wasn't trivial, since I had to explicitly tell igraph which nodes I want to merge by an ID vector i.e.: if you have four nodes with ids c(1,2,3,4) and you would like to merge the first three of them, you have to give the following id vector: c(1,1,1,2).
I used the data.table library too, since I'm more familiar with its syntax.
code :
dt <- as.data.table(A)
groupID <- dt[,.(gID = .GRP),by = list(dt$V1,dt$V2)]
colnames(dt) <- c('X','Y')
colnames(groupID) <- c('X','Y','gid')

dt[groupID, gID := i.gid, on = c(X = 'X', Y = 'Y')]

plot(contract.vertices(g,dt$gID),layout = as.matrix(groupID))
     X  Y gid
 1:  0  0   1
 2:  1  0   2
 3:  1 -1   3
 4:  1 -2   4
 5:  0 -2   5
 6: -1 -2   6
 7: -2 -2   7
 8: -2 -1   8
 9: -1 -1   9
10:  0 -1  10
11:  0 -3  11
12:  0 -4  12
13: -1 -4  13
14: -1 -3  14
15:  2 -2  15
16:  2 -3  16
17:  1 -3  17
     X  Y gID
 1:  0  0   1
 2:  1  0   2
 3:  1 -1   3
 4:  1 -2   4
 5:  0 -2   5
 6: -1 -2   6
 7: -2 -2   7
 8: -2 -1   8
 9: -1 -1   9
10:  0 -1  10
11:  0 -2   5
12:  0 -3  11
13:  0 -4  12
14: -1 -4  13
...
Related Posts Related Posts :
  • How can I debug a corrupt docx file?
  • Validating XML with standard XSD schema in Visual Studio 2017
  • flex: display number of children in datagrid column
  • Default namespace in XML file doesn't work with XSD, why?
  • Spring 3.1 : Cannot find the declaration of element 'beans'
  • Merging similar attributes with XSLT
  • WSO2 ESB: XML response in WSO2 REST API call not parsed
  • Add image id to image path based on condition
  • How to test data of an XML file
  • how can i solve "No grammar constraints (DTD or XML Schema) referenced in the document." WARNING
  • Why does XML not display in browser but correctly does in XML Notepad 2007 (Microsoft)?
  • How to output based on the input conditions
  • XML to Fixed width text file formatted details
  • Use parameter value as in select in xslt
  • Counting the number of times an xslt transform is done
  • Trouble using an environment variable's value in VBS
  • HTTP response containing XML book-ended by unexpected characters
  • Trying to retrieve just one node value in xslt
  • Select name of alias of xmlns atribute by xpath
  • Get and set text in a xml field
  • Need help to create an XSLT
  • Counting frequency of tags / attributes in XML using XSLT
  • Flat to Hierarchical XSLT Transform
  • XSL Selecting A Nested Field (From Shopify XML Output)
  • How do I add a semi colon between text fragments but not at the end of text fragments?
  • Parse XSL Date Format
  • Network protocol structure definitions in machine readable form (xml,json,other?)?
  • invalid byte '?' at position 2 of 2-byte sequence validation/parse error
  • Inserting a node into XML
  • Replace before and after string in vim
  • XML/XSL Table won't populate
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org