{"id":5195,"date":"2022-08-27T04:36:43","date_gmt":"2022-08-26T23:06:43","guid":{"rendered":"https:\/\/jassweb.com\/solved\/solved-sibling-as-child\/"},"modified":"2022-08-27T04:36:43","modified_gmt":"2022-08-26T23:06:43","slug":"solved-sibling-as-child","status":"publish","type":"post","link":"https:\/\/jassweb.com\/solved\/solved-sibling-as-child\/","title":{"rendered":"[Solved] Sibling as Child"},"content":{"rendered":"<p> [ad_1]<br \/>\n<\/p>\n<div id=\"answer-21598029\" class=\"answer js-answer accepted-answer js-accepted-answer\" data-answerid=\"21598029\" data-parentid=\"21587075\" data-score=\"0\" data-position-on-page=\"1\" data-highest-scored=\"1\" data-question-has-accepted-highest-score=\"1\" itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n<div class=\"post-layout\">\n<div class=\"votecell post-layout--left\"><\/div>\n<div class=\"answercell post-layout--right\">\n<div class=\"s-prose js-post-body\" itemprop=\"text\">\n<p>In XSLT 2.0, you could have probably made use of <strong>xsl:for-each-group<\/strong>, using its <strong>group-starting-with<\/strong> attribute. In XSLT 1.0 though, this can be achieved by use of keys. You can define a key to look up the <strong>Loop-2000B<\/strong> elements by their first preceding <strong>Loop-2000A<\/strong> element<\/p>\n<pre><code>&lt;xsl:key name=\"B\" match=\"ex:Loop-2000B\" use=\"generate-id(preceding-sibling::ex:Loop-2000A[1])\" \/&gt;\n<\/code><\/pre>\n<p>Similarlym you could do the same for associating <strong>Loop-2000C<\/strong> elements by their first preceding <strong>Loop-2000B<\/strong> element (Although this may not be necessary if you say there can be at most only one <strong>Loop-2000C<\/strong> element for each <strong>Loop-2000B<\/strong><\/p>\n<pre><code>&lt;xsl:key name=\"C\" match=\"ex:Loop-2000C\" use=\"generate-id(preceding-sibling::ex:Loop-2000B[1])\" \/&gt;\n<\/code><\/pre>\n<p>The <strong>generate-id<\/strong> function is an XSLT function that can be used to generate a unique id for each node (If one of their existing child elements could uniquely identify the element, you could also use that). Note the use of the <strong>ex:<\/strong> prefix is because all the elements in your XML are in a namespace, so XSLT needs to know which namespaces elements are in.<\/p>\n<p>In your XSLT you would start off by selecting just the <strong>Loop-2000A<\/strong> elements.<\/p>\n<pre><code>&lt;xsl:apply-templates select=\"ex:Loop-2000A\" \/&gt;\n<\/code><\/pre>\n<p>Then, within the template that matches <strong>ex:Loop-2000A<\/strong> you would select all the associated <strong>ex:Loop-2000B<\/strong> elements using the key<\/p>\n<pre><code>&lt;xsl:apply-templates select=\"key('B', generate-id(current()))\" \/&gt;\n<\/code><\/pre>\n<p>You would take a similar approach for getting the <strong>ex:Loop-2000C<\/strong> in the template that matches <strong>ex:Loop-2000B<\/strong>. Although, if there was ever only going to be at most one such <strong>ex:Loop-2000C<\/strong> element, you could do this and not worry about the key in this case:<\/p>\n<pre><code>&lt;xsl:apply-templates select=\"following-sibling::*[1][self::ex:Loop-2000C]\" \/&gt;\n<\/code><\/pre>\n<p>This gets the very following sibling element, but only if it is a <strong>Loop-2000C<\/strong> element.<\/p>\n<p>Finally, other existing elements can be matched and copied with the Identity Transform<\/p>\n<pre><code>&lt;xsl:template match=\"@*|node()\"&gt;\n  &lt;xsl:copy&gt;\n    &lt;xsl:apply-templates select=\"@*|node()\"\/&gt;\n  &lt;\/xsl:copy&gt;\n&lt;\/xsl:template&gt; \n<\/code><\/pre>\n<p>Try this XSLT<\/p>\n<pre><code>&lt;xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http:\/\/www.w3.org\/1999\/XSL\/Transform\" \n     xmlns:ex=\"http:\/\/www.example.org\"&gt;\n\n  &lt;xsl:output method=\"xml\" omit-xml-declaration=\"yes\" indent=\"yes\" \/&gt;\n  &lt;xsl:key name=\"B\" match=\"ex:Loop-2000B\" use=\"generate-id(preceding-sibling::ex:Loop-2000A[1])\" \/&gt;\n  &lt;xsl:key name=\"C\" match=\"ex:Loop-2000C\" use=\"generate-id(preceding-sibling::ex:Loop-2000B[1])\" \/&gt;\n\n  &lt;xsl:template match=\"*[ex:Loop-2000A]\"&gt;\n    &lt;xsl:copy&gt;\n      &lt;xsl:apply-templates select=\"@*\"\/&gt;\n      &lt;xsl:apply-templates select=\"ex:Loop-2000A\" \/&gt;\n      &lt;xsl:apply-templates select=\"*[not(self::ex:Loop-2000A)][not(self::ex:Loop-2000B)][not(self::ex:Loop-2000C)]\" \/&gt;\n    &lt;\/xsl:copy&gt;\n  &lt;\/xsl:template&gt;\n\n  &lt;xsl:template match=\"ex:Loop-2000A\"&gt;\n    &lt;xsl:copy&gt;\n      &lt;xsl:apply-templates select=\"@*\"\/&gt;\n      &lt;xsl:apply-templates select=\"key('B', generate-id(current()))\" \/&gt;\n      &lt;xsl:apply-templates \/&gt;\n    &lt;\/xsl:copy&gt;\n  &lt;\/xsl:template&gt;\n\n  &lt;xsl:template match=\"ex:Loop-2000B\"&gt;\n    &lt;xsl:copy&gt;\n      &lt;xsl:apply-templates select=\"@*\"\/&gt;\n      &lt;xsl:apply-templates select=\"key('C', generate-id(current()))\" \/&gt;\n      &lt;xsl:apply-templates \/&gt;\n    &lt;\/xsl:copy&gt;\n  &lt;\/xsl:template&gt;\n\n  &lt;xsl:template match=\"@*|node()\"&gt;\n    &lt;xsl:copy&gt;\n      &lt;xsl:apply-templates select=\"@*|node()\"\/&gt;\n    &lt;\/xsl:copy&gt;\n  &lt;\/xsl:template&gt;\n&lt;\/xsl:stylesheet&gt;\n<\/code><\/pre>\n<\/p><\/div>\n<div class=\"mt24\"><\/div>\n<\/div>\n<p>            <span class=\"d-none\" itemprop=\"commentCount\">2<\/span> <\/p><\/div>\n<\/div>\n<p>[ad_2]<\/p>\n<p>solved Sibling as Child <\/p>\n","protected":false},"excerpt":{"rendered":"<p>[ad_1] In XSLT 2.0, you could have probably made use of xsl:for-each-group, using its group-starting-with attribute. In XSLT 1.0 though, this can be achieved by use of keys. You can define a key to look up the Loop-2000B elements by their first preceding Loop-2000A element &lt;xsl:key name=&#8221;B&#8221; match=&#8221;ex:Loop-2000B&#8221; use=&#8221;generate-id(preceding-sibling::ex:Loop-2000A[1])&#8221; \/&gt; Similarlym you could do the &#8230; <a title=\"[Solved] Sibling as Child\" class=\"read-more\" href=\"https:\/\/jassweb.com\/solved\/solved-sibling-as-child\/\" aria-label=\"More on [Solved] Sibling as Child\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[320],"tags":[577,1023,1096],"class_list":["post-5195","post","type-post","status-publish","format-standard","hentry","category-solved","tag-xml","tag-xslt","tag-xslt-1-0"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>[Solved] Sibling as Child - JassWeb<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jassweb.com\/solved\/solved-sibling-as-child\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[Solved] Sibling as Child - JassWeb\" \/>\n<meta property=\"og:description\" content=\"[ad_1] In XSLT 2.0, you could have probably made use of xsl:for-each-group, using its group-starting-with attribute. In XSLT 1.0 though, this can be achieved by use of keys. You can define a key to look up the Loop-2000B elements by their first preceding Loop-2000A element &lt;xsl:key name=&quot;B&quot; match=&quot;ex:Loop-2000B&quot; use=&quot;generate-id(preceding-sibling::ex:Loop-2000A[1])&quot; \/&gt; Similarlym you could do the ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jassweb.com\/solved\/solved-sibling-as-child\/\" \/>\n<meta property=\"og:site_name\" content=\"JassWeb\" \/>\n<meta property=\"article:published_time\" content=\"2022-08-26T23:06:43+00:00\" \/>\n<meta name=\"author\" content=\"Kirat\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kirat\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-sibling-as-child\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-sibling-as-child\/\"},\"author\":{\"name\":\"Kirat\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\"},\"headline\":\"[Solved] Sibling as Child\",\"datePublished\":\"2022-08-26T23:06:43+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-sibling-as-child\/\"},\"wordCount\":279,\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"keywords\":[\"xml\",\"xslt\",\"xslt-1.0\"],\"articleSection\":[\"Solved\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-sibling-as-child\/\",\"url\":\"https:\/\/jassweb.com\/solved\/solved-sibling-as-child\/\",\"name\":\"[Solved] Sibling as Child - JassWeb\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#website\"},\"datePublished\":\"2022-08-26T23:06:43+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-sibling-as-child\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/jassweb.com\/solved\/solved-sibling-as-child\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-sibling-as-child\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/jassweb.com\/solved\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[Solved] Sibling as Child\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/jassweb.com\/solved\/#website\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"name\":\"JassWeb\",\"description\":\"Build High-quality Websites\",\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/jassweb.com\/solved\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\",\"name\":\"Jass Web\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"contentUrl\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"width\":693,\"height\":132,\"caption\":\"Jass Web\"},\"image\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\",\"name\":\"Kirat\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750\",\"contentUrl\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750\",\"caption\":\"Kirat\"},\"sameAs\":[\"http:\/\/jassweb.com\"],\"url\":\"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[Solved] Sibling as Child - JassWeb","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jassweb.com\/solved\/solved-sibling-as-child\/","og_locale":"en_US","og_type":"article","og_title":"[Solved] Sibling as Child - JassWeb","og_description":"[ad_1] In XSLT 2.0, you could have probably made use of xsl:for-each-group, using its group-starting-with attribute. In XSLT 1.0 though, this can be achieved by use of keys. You can define a key to look up the Loop-2000B elements by their first preceding Loop-2000A element &lt;xsl:key name=\"B\" match=\"ex:Loop-2000B\" use=\"generate-id(preceding-sibling::ex:Loop-2000A[1])\" \/&gt; Similarlym you could do the ... Read more","og_url":"https:\/\/jassweb.com\/solved\/solved-sibling-as-child\/","og_site_name":"JassWeb","article_published_time":"2022-08-26T23:06:43+00:00","author":"Kirat","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kirat","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jassweb.com\/solved\/solved-sibling-as-child\/#article","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/solved-sibling-as-child\/"},"author":{"name":"Kirat","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31"},"headline":"[Solved] Sibling as Child","datePublished":"2022-08-26T23:06:43+00:00","mainEntityOfPage":{"@id":"https:\/\/jassweb.com\/solved\/solved-sibling-as-child\/"},"wordCount":279,"publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"keywords":["xml","xslt","xslt-1.0"],"articleSection":["Solved"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/jassweb.com\/solved\/solved-sibling-as-child\/","url":"https:\/\/jassweb.com\/solved\/solved-sibling-as-child\/","name":"[Solved] Sibling as Child - JassWeb","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/#website"},"datePublished":"2022-08-26T23:06:43+00:00","breadcrumb":{"@id":"https:\/\/jassweb.com\/solved\/solved-sibling-as-child\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jassweb.com\/solved\/solved-sibling-as-child\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jassweb.com\/solved\/solved-sibling-as-child\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/jassweb.com\/solved\/"},{"@type":"ListItem","position":2,"name":"[Solved] Sibling as Child"}]},{"@type":"WebSite","@id":"https:\/\/jassweb.com\/solved\/#website","url":"https:\/\/jassweb.com\/solved\/","name":"JassWeb","description":"Build High-quality Websites","publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jassweb.com\/solved\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/jassweb.com\/solved\/#organization","name":"Jass Web","url":"https:\/\/jassweb.com\/solved\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/","url":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","contentUrl":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","width":693,"height":132,"caption":"Jass Web"},"image":{"@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31","name":"Kirat","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/","url":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750","contentUrl":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750","caption":"Kirat"},"sameAs":["http:\/\/jassweb.com"],"url":"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/"}]}},"_links":{"self":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/5195","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/comments?post=5195"}],"version-history":[{"count":0,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/5195\/revisions"}],"wp:attachment":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/media?parent=5195"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/categories?post=5195"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/tags?post=5195"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}