logo
down
shadow

XPath Get the following-sibling node with local-name due to namespace changing


XPath Get the following-sibling node with local-name due to namespace changing

By : Nick_Cav
Date : November 21 2020, 04:01 AM
it should still fix some issue You were close with what your have so far.
All you need is to replace *//* with * after following-sibling
code :
//*[local-name()='singer' and text() = 'Tom Waits']/following-sibling::*[local-name() = 'value']/text()


Share : facebook icon twitter icon
XPath following-sibling expression appears to return child text and not following-sibling node

XPath following-sibling expression appears to return child text and not following-sibling node


By : T.Bruce
Date : March 29 2020, 07:55 AM
With these it helps An element name is evaluated in the current context, so para[numlist] means "para with a child numlist element". Likewise:
code :
para[following-sibling::*[1]=numlist]
para[name(following-sibling::*[1])='numlist']
para[following-sibling::*[1]/self::numlist]
Using LibXML and XPath To Find Node With Colon (Local Namespace)

Using LibXML and XPath To Find Node With Colon (Local Namespace)


By : CREL
Date : March 29 2020, 07:55 AM
it should still fix some issue I think there's two problems here - first off, xpath expressions find nodes. You can search based on the existence and content of an attribute, but findnodes will give you the element, not the content.
Secondly - you can't nest namespaces in XML. x:ns2:Address isn't valid. Do you actually need to register your x namespace there? You may not need to at all. (e.g. based on your small XML snippet).
code :
#!/usr/bin/env perl
use strict;
use warnings;
use XML::Twig;

my $twig = XML::Twig->new( 'pretty_print' => 'indented_a' )->parse( \*DATA );

my @elt_list = grep { $_->trimmed_text =~ m{fubar\@test.com} }
    ( $twig->findnodes('//ns2:Address') );

foreach my $elt (@elt_list) {
    print $elt -> parent -> att('id1');
}


__DATA__
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Incomings xmlns:ns2="http://testme.org/foo/schema">
    <Incoming id1="6bbaec22" id2="928c2081">
        <ns2:Address>fubar@test.com</ns2:Address>
    </Incoming>     
</Incomings>
my @elt_list = ( $twig->findnodes("//ns2:Address[string()='$email']/../.[\@id1]") );

foreach my $elt (@elt_list) {
    print $elt -> att('id1');
}
use XML::Twig;

my $twig = XML::Twig->parsefile('your_file.xml'); 
print $twig -> findnodes('//Incoming',0)->att('id1'),"\n";
#!/usr/bin/env perl
use strict;
use warnings;
use XML::LibXML;

my $xml = XML::LibXML->new->parse_file( 'sample2.xml' );
foreach my $node (  $xml -> findnodes( '//Incoming' ) ) {
   print $node ->getAttribute('id1'), "\n";
} 
#!/usr/bin/env perl
use strict;
use warnings;
use XML::LibXML;

my $email = 'fubar@test.com';
my $xml = XML::LibXML->new->parse_file( 'sample2.xml' );
foreach my $node ( grep { $_ -> textContent =~ m{$email} } $xml -> findnodes( '//Incoming' ) ) {
   print $node ->getAttribute('id1'), "\n";
} 
#!/usr/bin/env perl
use strict;
use warnings;
use XML::LibXML;

my $xml   = XML::LibXML->new->parse_file('sample2.xml');
my $xpc   = XML::LibXML::XPathContext->new( $xml->documentElement );
$xpc->registerNs( 'x', 'http://testme.org/foo/schema' );

my $email = 'fubar@test.com';
my ( $id1 ) = map { $_ -> getAttribute('id1') // () } $xpc->findnodes("/Incomings/Incoming/x:Address[text()='$email']/..");
print $id1,"\n";
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]
XPath to Get Value from Sibling with Namespace

XPath to Get Value from Sibling with Namespace


By : Oddworld
Date : March 29 2020, 07:55 AM
wish help you to fix your issue Don't use local-name(). Declare the namespaces in your XSLT and use the prefixes.
For example, declare them like this (you can pick any prefixes you like, as long as the namespace URIs match):
code :
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:msg="http://www.caps-solutions.co.uk/webservices/connectors/731/servicerequest/messagetypes"
  xmlns:sr="http://www.caps-solutions.co.uk/schema/uniform/731/servicerequest/sr/srtypes"
  xmlns:uni="http://www.caps-solutions.co.uk/schema/uniform/72b/common/uniformtypes"
  exclude-result-prefixes="msg sr uni"
>
/msg:GetGeneralServiceRequestByReferenceValueResponse
/sr:GeneralServiceRequest
/sr:ServiceRequestIdentification
/sr:AlternativeReferences
/uni:AlternativeReference[uni:ReferenceType = 'UTRN']
/uni:ReferenceValue
//uni:ReferenceType[. = 'UTRN']/../uni:ReferenceValue
//uni:AlternativeReference[uni:ReferenceType = 'UTRN']/uni:ReferenceValue
XPath Get Value based on sibling value - with namespace

XPath Get Value based on sibling value - with namespace


By : Ryuga
Date : March 29 2020, 07:55 AM
seems to work fine There are lots of answers with no namespaces involved but I'm having trouble with the namespace. , You can add
code :
/*[local-name()="Value" and preceding-sibling::*[local-name()="Name" and .="Email"]]
Related Posts Related Posts :
  • Setting xml to body
  • XSL-FO image path problems - changing backslashes to forward
  • XSLT test expression to check how many levels deep the URL is
  • Using SimpleType on Element Type
  • Insert node into XML without using sql:variable
  • Android Studio Vector Assets - How to merge/combine two vector assets together?
  • How to extract XML with XSLT based on list index condition?
  • How do you merge two same-format xml files using xQuery so that the merged file is ordered by timestamp?
  • XPath for an <address> tag using ImportXML in Google Sheets
  • How to Extract a Specific XML Node using SED
  • How to find and replace on patterns like ‘something=“string”’ on Linux?
  • obtaining information from xml file via power shell in an attempt to uninstall application
  • XSLT For-Each Only Selecting First Element
  • Relitve path for MSXML2.ServerXMLHTTP.6.0 not working
  • Conditional templates based on global variable
  • Using an XML element value in an XSLT predicate
  • XML file and text files!
  • Loading special characters in a string loaded via XML in AS3
  • How to parse a xml by ANT
  • Is it possible to generate a XSL-FO template from a PDF?
  • outputting XML encapsulated literal using XSLT
  • XSD force to use a particular order for the element with attribute
  • Endless runtime for a script that sometimes works
  • How do I properly insert an XML document into another using rexml?
  • Is there a comprehensive guide for Weblogic Scripting Tool (WLST)
  • XSLT: Check if any group of elements have a child element with a specified value
  • How to compile a schema that uses a DataSet (xs:schema)?
  • Trouble with error #1067: Implicit coercion of a value of type String to an unrelated type XML - AS3
  • Passing JDBC url from Maven to hibernate.cfg.xml
  • shadow
    Privacy Policy - Terms - Contact Us © bighow.org