logo
down
shadow

Fetch sibling nodes linq


Fetch sibling nodes linq

By : Mirnox
Date : October 18 2020, 03:08 PM
I hope this helps you . You're close, you're just forgetting to check the Value property
code :
.Where(i => i.Element("content").Element("path").Value == mypath)


Share : facebook icon twitter icon
XSLT 1.0 - Merge sibling nodes with child nodes into new composite nodes

XSLT 1.0 - Merge sibling nodes with child nodes into new composite nodes


By : nevech
Date : March 29 2020, 07:55 AM
Hope this helps I had a tough time formulating the question title. Maybe the example will make more sense. , This transformation is quite simpler (only 3 templates and no modes):
code :
<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:key name="kTypeByVal" match="@type" use="."/>

 <xsl:key name="kPhNumByType" match="phone_number"
  use="@type"/>

 <xsl:key name="kAddrByType" match="email_address"
  use="@type"/>

 <xsl:variable name="vallTypes" select=
 "/*/*/*/@type
          [generate-id()
          =
           generate-id(key('kTypeByVal',.)[1])
          ]"/>

 <xsl:template match="/">
  <root>
   <addresses>
    <xsl:apply-templates select="$vallTypes"/>
   </addresses>
  </root>
 </xsl:template>

 <xsl:template match="@type">
  <xsl:variable name="vcurType" select="."/>
  <xsl:variable name="vPhoneNums" select="key('kPhNumByType',.)"/>
  <xsl:variable name="vAddresses" select="key('kAddrByType',.)"/>

  <xsl:variable name="vLonger" select=
  "$vPhoneNums[count($vPhoneNums) > count($vAddresses)]
  |
   $vAddresses[not(count($vPhoneNums) > count($vAddresses))]
  "/>

  <xsl:for-each select="$vLonger">
   <xsl:variable name="vPos" select="position()"/>
   <address name="{$vcurType}{$vPos}">
    <xsl:apply-templates select="$vPhoneNums[position()=$vPos]"/>
    <xsl:apply-templates select="$vAddresses[position()=$vPos]"/>
   </address>
  </xsl:for-each>
 </xsl:template>

 <xsl:template match="phone_number|email_address">
  <xsl:copy>
   <xsl:copy-of select="node()"/>
  </xsl:copy>
 </xsl:template>
</xsl:stylesheet>
<root>
    <phone_numbers>
        <phone_number type="work">123-WORK</phone_number>
        <phone_number type="home">456-HOME</phone_number>
        <phone_number type="work">789-WORK</phone_number>
        <phone_number type="other">012-OTHER</phone_number>
    </phone_numbers>
    <email_addresses>
        <email_address type="home">a@home</email_address>
        <email_address type="other">b@other</email_address>
        <email_address type="home">c@home</email_address>
        <email_address type="work">d@work</email_address>
        <email_address type="other">e@other</email_address>
        <email_address type="other">f@other</email_address>
    </email_addresses>
</root>
<root>
   <addresses>
      <address name="work1">
         <phone_number>123-WORK</phone_number>
         <email_address>d@work</email_address>
      </address>
      <address name="work2">
         <phone_number>789-WORK</phone_number>
      </address>
      <address name="home1">
         <phone_number>456-HOME</phone_number>
         <email_address>a@home</email_address>
      </address>
      <address name="home2">
         <email_address>c@home</email_address>
      </address>
      <address name="other1">
         <phone_number>012-OTHER</phone_number>
         <email_address>b@other</email_address>
      </address>
      <address name="other2">
         <email_address>e@other</email_address>
      </address>
      <address name="other3">
         <email_address>f@other</email_address>
      </address>
   </addresses>
</root>
how to write XSLT to repeat a sibling nodes value with every occurence of its sibling in a HTML table

how to write XSLT to repeat a sibling nodes value with every occurence of its sibling in a HTML table


By : Nayos
Date : March 29 2020, 07:55 AM
I hope this helps . The following stylesheet produces what I believe the desired output is:
code :
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:variable name="lower" select="'abcdefghijklmnopqrstuvwyzy'"/>
    <xsl:variable name="upper" select="'ABCDEFGHIJKLMNOPQRSTUVWYZY'"/>

    <xsl:template match="/">     
        <html>    
            <xsl:apply-templates select="ClientImport"/>       
        </html> 
    </xsl:template> 

    <xsl:template match="ClientImport">     
        <table border="1">
            <tr>
                <xsl:apply-templates select="episode[1]/@localID" mode="header"/>
                <xsl:apply-templates select="episode[1]/episodeDetails[1]/*" mode="header"/>
                <xsl:apply-templates select="episode[1]/dailyInterventions[1]/dailyIntervention[1]/*" mode="header"/>
            </tr>
            <xsl:apply-templates select="episode"/>                 
        </table>         
    </xsl:template>

    <xsl:template match="@*|*" mode="header">
        <th><xsl:value-of select="translate(local-name(), $lower, $upper)"/></th>
    </xsl:template>

    <xsl:template match="episode"> 
        <xsl:apply-templates select="dailyInterventions/dailyIntervention"/>
    </xsl:template>

    <xsl:template match="@localID">
        <td><xsl:value-of select="."/></td> 
    </xsl:template>

    <xsl:template match="episodeDetails">
        <xsl:apply-templates select="../@localID"/>
        <xsl:apply-templates select="*"/>
    </xsl:template>

    <xsl:template match="dailyInterventions/dailyIntervention"> 
        <tr>
            <xsl:apply-templates select="../preceding-sibling::episodeDetails" />
            <xsl:apply-templates select="*"/>
        </tr>     
    </xsl:template>

    <xsl:template match="episodeDetails/* | dailyIntervention/*">
        <td><xsl:value-of select="."/></td>
    </xsl:template>

</xsl:stylesheet>
How to fetch some specific XML nodes present only in few parents using LINQ for XML?

How to fetch some specific XML nodes present only in few parents using LINQ for XML?


By : Manishankar D K
Date : March 29 2020, 07:55 AM
around this issue I have been struggling to fetch some specific nodes of my XML. Problem is that the node may or may not be present in the nth level. I have shared my XML below : , Just don't forget to use the default xml namespace
code :
var xDoc = XDocument.Load(filename);
XNamespace ns = xDoc.Root.GetDefaultNamespace();
//OR XNamespace ns = "http://schemas.microsoft.com/developer/msbuild/2003";

var nodes = xDoc.Descendants(ns + "ClCompile").ToList();
var filter = nodes[i].Element(ns + "Filter");
xPath: select a range of sibling nodes until a specific sibling node

xPath: select a range of sibling nodes until a specific sibling node


By : Gangadharr Bauri
Date : March 29 2020, 07:55 AM
I wish this help you How are you using the xpath?
If you are merely looping through the supercategories and thus know their positions and can build the xpath dynamically you can simply count the preceding subercategories.
code :
//li[@class="supercategory"][position()=2]/following-sibling::li[@class ="subcategory"][count(preceding-sibling::li[@class='supercategory']) = 2]
Find if two nodes are cousin nodes or sibling nodes in Binary Tree in JavaScript

Find if two nodes are cousin nodes or sibling nodes in Binary Tree in JavaScript


By : Saurabh
Date : March 29 2020, 07:55 AM
this will help You could store the path to the wanted nodes and check the same length of the pathes and the last or the element before the last for getting the relation.
code :
function getPath(node, value, path = []) {
    if (!node) {
        return;
    }
    if (node.value === value) {
        return path;
    }
    return getPath(node.left, value, path.concat(node.value))
        || getPath(node.right, value, path.concat(node.value));
}

function findRelation(root, a, b) {
    var pathA = getPath(root, a),
        pathB = getPath(root, b);

    if (pathA.length !== pathB.length) {
        return;
    }
    if (pathA.length && pathA[pathA.length - 1] === pathB[pathB.length - 1]) {
        return 'siblings';
    }

    if (pathA.length > 1 && pathA[pathA.length - 2] === pathB[pathB.length - 2]) {
        return 'cousins';
    }
}

var tree = { value: 3, left: { value: 2, left: { value: 1 } }, right: { value: 4, right: { value: 5 } } };

console.log(findRelation(tree, 2, 4));
console.log(findRelation(tree, 1, 5));
Related Posts Related Posts :
  • EF junction table with additional Id throws exception on save
  • Asp.net core model doesn't bind from form
  • Asp Net Core WebHostBuilder strange behavior during integration testing
  • Which corner case unit test would this fail?
  • Property injection not working
  • Adding Signature Line Word-Excel
  • ediFabric 6.7.7 - validation of generic EDI message
  • How to use System.Runtime.CompilerServices.RuntimeHelpers.PrepareMethod with CoreCLR and CoreFX?
  • run batch file xcopy from .NET (C#) and get the result
  • Use "Optional, DefaultParameterValue" attribute, or not?
  • Automapper Map.CreateMap not used anymore?
  • C# , MVC , EnityFramework , How to processing data
  • How can I optionally include an external library?
  • How to join tables using LINQ and navigation properties
  • Deserialize Bytes Array directly to Object in JSON.Net
  • FileNotFoundException, but catch block is not entered (Async method)
  • How does GameRanger works?
  • See the AvailableFreeSpace of drives via IP-Address
  • How to convert Sql Datetime query into Linq
  • Email sending always fails, what is wrong with my contact us code
  • how to get a part from a string with regular expression in C#
  • Mapping List`1 to Object properties
  • Handle UnauthorizedAccessException When Directory.CreateDirectory() Run
  • Whats the equivalent of C# "Click.add" for Visual Basic .net
  • C# - Need help generating a random number and using the same number multiple times in other functions
  • WPF Binding StringFormat doesn't change the output
  • Convert Expression<Func<TDocument, object>> to Expression<Func<TDocument, TOutput>>
  • How do I save current user in another table when saving objects?
  • CLOCKS_PER_SEC equivalent in C#
  • Unable to start debugging on the web server. Operation not supported. Unknown error 0x800040005
  • Why is private variable of another class accessible inside .Equals override?
  • Why does HttpClient continue to fail during subsequent retries using Polly?
  • How to create autocompletion in Excel?
  • image problems with webcamtexture
  • Most efficient way to search enumerable
  • How to pass array property in model Asp.net Core in HttpGet?
  • Installing a .NetStandard 2.0 Nuget package into a VS2015 Net 4.6.1 project
  • How to sum a field on linq that has a where clause which pulls data that returns nulls too?
  • Can we assign more RAM to a program that gets an OutOfMemoryException
  • GC Alloc for unknown reason
  • How to address "You are using an unsupported command-line flag: --ignore-certificate-errors, Stability and security
  • get image url from SharePoint genericlist with CSOM
  • Calculate difference between datetime and convert to int
  • The type or namespace name `IGraphResult` could not be found. But it's there and it works fine elsewhere
  • Using MEF in an Azure function App
  • How to listen for Pub/Sub messages in an ASP.NET Core app continuously?
  • How to store multiple checked Checkbox values in DB using ASP.NET MVC
  • What causes this amazon build error in UWP Release mode?
  • Callback function end after creating instance of class (c#)
  • Is there a way to perform a chained null check in a dynamic/expando?
  • SimpleInjector lazy generic registration
  • SD card directory
  • System.Net.Http in net47
  • C++ how to implement an array of list
  • Xamarin Forms Displaying the list of email recipients
  • run and handle output from ps1 script
  • How to set change log entries user in Dynamics Nav 2016
  • Is it possible to query all companies via ODATA in Dynamics Nav 2016
  • Reading Json Content and Displaying it
  • Is BouncyCastle's SecureRandom in C# threadsafe?
  • shadow
    Privacy Policy - Terms - Contact Us © soohba.com