Given
<catalogue>
<produits>
<produit id="pdt1" libelle="produit 1" cat="PDT">
<metas date="2015.07.24">
<meta code="123456" value="123456">
<meta code="789012" value="ghijkl">
<meta code="345678" value="mnopqr">
</metas>
</produit>
<produit id="pdt2" libelle="produit 2" cat="PDT">
<metas date="2015.07.24">
<meta code="123456" value="abcdef">
<meta code="789012" value="ghijkl">
<meta code="345678" value="mnopqr">
</metas>
</produit>
<produit id="pdt3" libelle="produit 3" cat="PDT">
<metas date="2015.07.24">
<meta code="123456" value="123456">
<meta code="789012" value="ghijkl">
<meta code="345678" value="mnopqr">
</metas>
</produit>
</produits>
</catalogue>
<catalogue>
<produits>
<produit id="pdt1" libelle="produit 1" cat="PDT">
<metas date="2015.07.24">
<meta code="123456" value="123456">
<meta code="789012" value="ghijkl">
<meta code="345678" value="mnopqr">
</metas>
</produit>
<produit id="pdt2" libelle="produit 2" cat="PDT">
<metas date="2015.07.24">
<meta code="123456" value="abcdef">
<meta code="789012" value="ghijkl">
<meta code="345678" value="mnopqr">
</metas>
</produit>
<produit id="pdt3" libelle="produit 3" cat="PDT">
<metas date="2015.07.24">
<meta code="123456" value="123456">
<meta code="789012" value="ghijkl">
<meta code="345678" value="mnopqr">
</metas>
</produit>
</produits>
</catalogue>
Required: Find the values of id if their sub-node meta contains 123456.
My attempt:
I can access meta elements using //meta[#* = "123456"] I need to select ancestors ids.
source: http://practicalsqa.net/beginning-brainteaser-querying-subchildren/
UPDATE
Thanks #CiaPan for correcting 2 errors in the above XML, the correct one is:
<data>
<catalogue>
<produits>
<produit id="pdt1" libelle="produit 1" cat="PDT">
<metas date="2015.07.24">
<meta code="123456" value="123456" />
<meta code="789012" value="ghijkl" />
<meta code="345678" value="mnopqr" />
</metas>
</produit>
<produit id="pdt2" libelle="produit 2" cat="PDT">
<metas date="2015.07.24">
<meta code="123456" value="abcdef" />
<meta code="789012" value="ghijkl" />
<meta code="345678" value="mnopqr" />
</metas>
</produit>
<produit id="pdt3" libelle="produit 3" cat="PDT">
<metas date="2015.07.24">
<meta code="123456" value="123456" />
<meta code="789012" value="ghijkl" />
<meta code="345678" value="mnopqr" />
</metas>
</produit>
</produits>
</catalogue>
<catalogue>
<produits>
<produit id="pdt1" libelle="produit 1" cat="PDT">
<metas date="2015.07.24">
<meta code="123456" value="123456" />
<meta code="789012" value="ghijkl" />
<meta code="345678" value="mnopqr" />
</metas>
</produit>
<produit id="pdt2" libelle="produit 2" cat="PDT">
<metas date="2015.07.24">
<meta code="123456" value="abcdef" />
<meta code="789012" value="ghijkl" />
<meta code="345678" value="mnopqr" />
</metas>
</produit>
<produit id="pdt3" libelle="produit 3" cat="PDT">
<metas date="2015.07.24">
<meta code="123456" value="123456" />
<meta code="789012" value="ghijkl" />
<meta code="345678" value="mnopqr" />
</metas>
</produit>
</produits>
</catalogue>
</data>
In order not to use complex Xpath Axises, you could select an item which has a specific child by this logic:
item[.//someShild]
so required xpath is:
//produit[.//meta[#value=123456]]/#id
or you can select all items with specific meta by //produit[.//meta[#value=123456]] and get ids with another tool
Find all appropriate meta elements, then look for their ancestors.
If you're interested in a given value in specified two attributes:
/descendant::meta[ (#code, #value)="123456"]/ancestor::*/#id
If the value may be found in any attribute of meta element:
distinct-nodes( /descendant::meta[ #* = "123456"]/ancestor::*)/#id
You can also work the other way: scan all elements with id attributes, test their meta descendant elements and return id attributes for those meeting criteria:
/descendant::*[ #id and descendant::meta[ #* = "123456"]]/#id
Related
I have the following fragment. I'm trying to extend the base fragment "head" with the open graph tags... but the rendered page contains only tags from fragments/head, with the og ones.
How can I add more tags to a fragment?
<head th:include="fragments/head :: head">
<!-- You can use Open Graph tags -->
<meta property="og:url" th:content="${url}" />
<meta property="og:type" content="website" />
<meta property="og:title" content="GUApp" />
<meta property="og:description" th:content="${description}" />
<!--<meta property="og:image" content="http://www.your-domain.com/path/image.jpg" />-->
</head>
<head th:fragment="head" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
....
</head>
The easiest option is to pass additional tags as in Flexible layouts documentation demo.
Thanks to fragment expressions, we can specify parameters for
fragments that are not texts, numbers, bean objects… but instead
fragments of markup.
This allows us to create our fragments in a way such that they can be
enriched with markup coming from the calling templates, resulting in a
very flexible template layout mechanism.
index.html
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head th:include="header :: head(~{::meta})">
<!-- You can use Open Graph tags -->
<meta property="og:url" th:content="${url}"/>
<meta property="og:type" content="website"/>
<meta property="og:title" content="GUApp"/>
<meta property="og:description" th:content="${description}"/>
</head>
...
header.html
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head th:fragment="head(meta)">
<!-- some default styles -->
<link href="base.css" rel="stylesheet" />
<!--/* Per-page placeholder for additional meta tags */-->
<th:block th:replace="${meta}" />
</head>
...
Result html:
<!DOCTYPE html>
<html lang="en">
<head>
<link href="base.css" rel="stylesheet" />
<meta property="og:url"/>
<meta property="og:type" content="website"/>
<meta property="og:title" content="GUApp"/>
<meta property="og:description"/>
</head>
...
we have this code for each product:
<meta property="og:type" content="product" />
<meta property="og:site_name" content="Lotuscrafts" />
<meta property="og:url" content="http://www.example.com/yogadecke-savasana-100-baumwolle-kba" />
<meta property="og:title" content="Yogadecke "Savasana" 100% Baumwolle (kbA)" />
<meta property="og:description" content=" Vielseitig anwendbar in der Yogapraxis Klassische, handgewebte Yogadecke, ideal als unterstützende Unterlage in der Asana Praxis, im Meditationssitz oder für die Endentspannung. Aus 100% Baumwolle, ökologisch gefertigt Gefertigt..." />
<meta property="og:image" content="http://www.example.com/media/image/d2/6b/12/YBL-BO55f6c92eb882a.jpg" />
<meta property="product:brand" content="Yogi" />
<meta property="product:price" content="29,95" />
<meta property="product:product_link" content="http://www.example.com/yogadecke-savasana-100-baumwolle-kba" />
In the Pinterest docs (https://developers.pinterest.com/docs/rich-pins/products/) I can see that product:price:amount and product:price:currency are required. In the example code it's mentioned this code (og instead of product as written in the docs)
<meta property="og:price:amount" content="98.00" />
<meta property="og:price:currency" content="USD" />
Which one is correct? Does anybody know?
Pinterest no longer supports price variations or ranges unless you are using a feed partner like Shopify.
I like clean code and I'm sure most developers do. I am coming across an issue where my Meta tags are all appearing on ONE line all together and not on separate lines.
I have a file called "client.master" and here is code for the header:
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="default" />
<meta name="format-detection" content="telephone=no" />
<script src="/scripts/script1.min.js" type="text/javascript"></script>
<script src="/scripts/script2.min.js" type="text/javascript"></script>
<link rel="apple-touch-icon" href="/images/home-screen.png" />
<link rel="apple-touch-startup-image" href="/images/home-startup.png" />
<link href="/css/thirdparty/xxxxx.min.css" type="text/css" rel="stylesheet" />
<link href="/css/design.css" type="text/css" rel="stylesheet" />
<asp:ContentPlaceHolder ID="headContent" runat="server">
</asp:ContentPlaceHolder>
</head>
That looks very clean and nice. However, when I view the source of the page, the output shows the <meta> tags and the <link> tags all on one line. The script tags are not.
Here is the output of my code:
<!DOCTYPE html>
<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" /><meta name="apple-mobile-web-app-capable" content="yes" /><meta name="apple-mobile-web-app-status-bar-style" content="default" /><meta name="format-detection" content="telephone=no" />
<script src="/scripts/script1.min.js" type="text/javascript"></script>
<script src="/scripts/script2.min.js" type="text/javascript"></script>
<link rel="apple-touch-icon" href="/images/home-screen.png" /><link rel="apple-touch-startup-image" href="/images/home-startup.png" /><link href="/css/thirdparty/xxxxx.min.css" type="text/css" rel="stylesheet" /><link href="/css/design.css" type="text/css" rel="stylesheet" />
<title>
Login
</title></head>
Notice the <meta> and <link> tags are both on a single line AND the <title> tag has line breaks.
Here is the HTML for the default.aspx page for the Title:
<asp:Content ID="title" runat="server" ContentPlaceHolderID="title">
Login
</asp:Content>
My assumption is because the <meta> tags and <link> tags are self enclosed and the <script> tags end with </script>.
Is the only way to resolve this issue to close my <meta> tags with </meta>. Which way is to be considered the standard when closing meta and link tags? or script tags?
Thanks in advance for your help!
If you really want to follow the spec, link and meta are void elements, they can't have a closing tag, if your DOCTYPE is HTML5, you can use the selfclosing tag <meta ..../> but the default way would be to use it only as a start tag, that is a correct conforming use as empty elements don't need an end tag (void ones, as I said, can't have it).
Script is not a void element, but is an empty one, so you can use only the start tag, the self-closing tag or both start and end tags.
Note that for an element to have a content model of type empty really means it may be empty, not that it should; that would probably be what it is called void.
As to why the asp parser does that to your metas, I can't think of a reason. I understand your preference for clean code, but if it is of any help, try to think that at least that bug contributes to a filesize decrease :o)
Bear in mind that all of this applies to HTML5, XHTML treats void and empty models differently.
I got a problem with the internationalization of Open Oraph objects.
When I ask the scraper to scrape my opengraph objects in a specific locale, the object is first scraped in the default locale, i.e. without parameter fb_locale, and afterwards it is scraped in the correct locale, i.e. with fb_locale=[LOCALE]. The return of the scrape contains the result of the first default locale (en_US) scrape and the object is not shown in the correct locale neither in the chronic nor in the feed.
Here are my calls:
Call the scraper
POST https://graph.facebook.com
id http://apps.facebook.com/[APP_NAMESPACE]/?ogObjType=prize&ogObjId=1&ogObjVariant=
scrape true
locale de_DE
Then the first scrape is done by Facebook:
GET [GAME_HOST]?ogObjType=prize&ogObjId=1&ogObjVariant
Returns:
<html><head prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb# [APP_NAMESPACE]: http://ogp.me/ns/fb/[APP_NAMESPACE]#">
<meta property="og:locale" content="en_US" />
<meta property="og:locale:alternate" content="de_DE" />
<meta property="og:locale:alternate" content="en_US" />
<meta property="og:locale:alternate" content="fr_FR" />
<meta property="fb:app_id" content="[APP_ID" />
<meta property="og:type" content="[APP_NAMESPACE]:prize" />
<meta property="og:url" content="http://apps.facebook.com/[APP_NAMESPACE]/?ogObjType=prize&ogObjId=1&ogObjVariant" />
<meta property="og:title" content="Golden Medal" />
<meta property="og:description" content="A Golden Medal" />
<meta property="og:determiner" content="the" />
<meta property="og:image" content="[IMAGE_en_US_URL]" />
</head><body...</body></html>
Then the second scrape is done by facebook:
GET [GAME_HOST]?ogObjType=prize&ogObjId=1&ogObjVariant&fb_locale=de_DE
Returns:
<html><head prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb# [APP_NAMESPACE]: http://ogp.me/ns/fb/[APP_NAMESPACE]#">
<meta property="og:locale" content="de_DE" />
<meta property="og:locale:alternate" content="de_DE" />
<meta property="og:locale:alternate" content="en_US" />
<meta property="og:locale:alternate" content="fr_FR" />
<meta property="fb:app_id" content="[APP_ID]" />
<meta property="og:type" content="[APP_NAMESPACE]:prize" />
<meta property="og:url" content="http://apps.facebook.com/[APP_NAMESPACE]/?ogObjType=prize&ogObjId=1&ogObjVariant" />
<meta property="og:title" content="Goldmedaille" />
<meta property="og:description" content="Eine Goldmedaille" />
<meta property="og:determiner" content="the" />
<meta property="og:image" content="[IMAGE_de_DE_URL]" />
</head><body>...</body></html>
The scraper returns:
{"url":"http:\/\/apps.facebook.com\/[APP_NAMESPACE]\/?ogObjType=prize&ogObjId=1&ogObjVariant",
"type":"[APP_NAMESPACE]:prize",
"title":"Golden Medal",
"locale":{"locale":"en_us","alternate":["de_de","en_us","fr_fr"]},
"image":[{"url":"[IMAGE_en_US_URL]"}],
"description":"A Golden Medal",
"site_name":"[APP_NAME]",
"determiner":"the",
"updated_time":"2012-08-21T08:58:57+0000",
"id":"[SOME_ID]",
"application":{"id":"[APP_ID]","name":"[APP_NAME]","url":"http:\/\/www.facebook.com\/apps\/application.php?id=[APP_ID]"}}
Do you have any suggestions, why the object is scraped twice and the localized version is not stored?
Even with the meta properties, FB is still fetching the wrong image.
Here is my head:
<title>5mm 70L Full Wave LED 5-multi Holiday Lights</title>
<meta name="description" content="5mm 70L Full Wave LED 5-multi Holiday Lights - The LED Warehouse" />
<meta name="keywords" content="5mm,70L,Full,Wave,LED,5-multi,Holiday,Lights" />
<meta name="GOOGLEBOT" content="index,follow" />
<meta name="robots" content="index,follow" />
<link rel="shortcut icon" href="favicon.ico" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta property="og:title" content="5mm 70L Full Wave LED 5-multi Holiday Lights" />
<meta property="og:type" content="product" />
<meta property="og:url" content="http://testing.environmentalled.com/5mm-70L-Full-Wave-LED-5-multi-Holiday-Lights-p105.html"/>
<meta property="og:image" content="http://www.environmentalled.com/images/products/839.jpg"/>
<meta property="og:site_name" content="The LED Warehouse" />
<meta property="fb:admins" content="100001735835873" />
<link href="/style-led.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="/js/magiczoom.js"></script>
I use these meta properties on other non php pages without any issue.
From the og:url you specified: http://testing.environmentalled.com/5mm-70L-Full-Wave-LED-5-multi-Holiday-Lights-p105.html
From that the linter sees:
Meta Tag: <meta property="og:title" content="5mm 70L Full Wave LED 5-multi Holiday Lights" />
Meta Tag: <meta property="og:type" content="product" />
Meta Tag: <meta property="og:url" content="http://testing.environmentalled.com/5mm-70L-Full-Wave-LED-5-multi-Holiday-Lights-p105.html" />
Meta Tag: <meta property="og:image" content="http://www.environmentalled.com/images/products/839.jpg" />
Meta Tag: <meta property="og:site_name" content="The LED Warehouse" />
Meta Tag: <meta property="fb:admins" content="100001735835873" />
Is this incorrect?
The only thing the linter says is that it cannot find og:description.
Is http://www.environmentalled.com/images/products/839.jpg the correct image you want?