Exclude elements from Xpath groups - html

I have a very complex HTML of a website. I want to select multiple groups of elements by relative Xpath. For example:
//div[#class="something] | //span/div | //div/span/div[#class="otherthing"]
Once I have all elements selected I want to exclude some specific elements within the same xpath.
Let's say the xpath above returned 150 elements as a result. I want to exclude the following 3 xpaths which all point to 1 element each. So the end result should be 147 elements found:
//div[#id="menu"]
//div/span/div[#class="something3"]
//body/span/div/span/div[1]
How can I do this within 1 xpath with Xpath 1?
I have tried the solution here, however this only works while you are selecting one group you would like to exclude from: https://stackoverflow.com/a/74615054/12366148
I have also tried multiple ways to combine the 'not' and 'self' commands, however nothing seems to work. I can't use the except operator unfortunately as that only works in Xpath 2.0.

Given <xsl:variable name="ns1" select='//div[#class="something] | //span/div | //div/span/div[#class="otherthing"]'/> and <xsl:variable name="ns2" select='//div[#id="menu"] | //div/span/div[#class="something3"] | //body/span/div/span/div[1]'/>, you can use e.g.
<xsl:variable name="ns1-except-ns2" select="$ns1[count(. | $ns2) != count($ns2)]"/>
if my XPath 1 recollection still works.
You haven't used an XSLT tag so I guess you want
(//div[#class="something] | //span/div | //div/span/div[#class="otherthing"])[count(. | //div[#id="menu"] | //div/span/div[#class="something3"] | //body/span/div/span/div[1]) != count(//div[#id="menu"] | //div/span/div[#class="something3"] | //body/span/div/span/div[1])]

Related

Recursive tags hierarchy retrieval in sql

(Assumption: each tag may have a parent tag, i.e. there exist a hierarchy of tags, without limiting its depth.)
Is there a way (possibly with just one query) to retrieve all the children tags of a tag with just SQL, i.e. without using a code?
The problem is:
I have a hierarchy of tags:
root-tag
- tag-child -> parent is tag-child
-- tag-child-depth-2 -> parent is tag-child-depth-2
--- tag-child-depth-3 -> parent is root-tag
- tag-other-child -> parent is root-tag
This could be represented in DB this way:
id | tag_name | parent_tag_id
-------------------------------------------------
1 | root-tag | (NULL)
2 | tag-child | 1
I have been only given the top tag ("root-tag"). How to rerieve all the child tags?
Expected result:
All the children tags (except root parent tag).
i.e.:
- tag-child
-- tag-child-depth-2
--- tag-child-depth-3
- tag-other-child
The actual way of represeting the result data is not that important (i.e. this could be a simple list / array), however the most valuable would be a recursive array, maintaining the hierarchy - it's not obligatory though of course.

can't insert tables within dd tags in markdown syntax

setting up documentation for a plugin.
Can you add tables within a dd tag?
I tried the code below but it wont output as a table I tried with the double space line break technique but nothing either
This doesnt parse the table and just leaves the table syntax as is
Term
: definition
: | Table cell | Table cel | Table cell |
This wont render (note there are two spaces after definition)
Term
: definition
| Table cell | Table cel | Table cell |
my goal is this:
<dl>
<dt>Term</dt>
<dd>
definition
<table>
<!-- table rows and cells here -->
</table>
</dd>
</dl>
Depending on the Markdown implementation you are using either you can't or you need to do three things:
(1) Wrap your table with blank lines
A table is a block level element, just like a paragraph is. Therefore, it needs to be on a line by itself. To accomplish that, you need to include a blank line before the table. There is no need to add two spaces to the preceding line as the blank line already separates the elements and each block-level element will always be on its own line (barring some non-standard CSS which changes that behavior) .
(2) Indent your table
Of course, when you are nesting block level elements inside a list item and those elements do not start in the first line of the list item, you must indent those elements by one level to indicate they are nested. Therefore, the table must be indented by four spaces or one tab.
(3) Add a table header
Except for Kramdown, all implementations which support tables (that I am aware of) require the table to include a header. Otherwise, they do not recognize it as a table.
Example
Try this:
Term
: definition
| Header 1 | Header 2 | Header 3 |
| ---------- | --------- | ---------- |
| Table cell | Table cel | Table cell |
That said, both definition lists and tables are non-standard Markdown and their behavior varies among implementations which support them (not all do). Therefore, YMMV.
In fact, Babelmark demonstrates that the above works for Pandoc, RDiscount, PHP Markdown Extra, and MultiMarkdown (strangely version 5, but not version 6). Note that a few other implementations likely would work as well if they were properly configured. Babelmark only demonstrates default behavior for each implementation.

How to get an element using CSS or Xpath by removing a specific text?

I need to get an element using CSS or XPath by searching by its text inside a list, each element contains the Project Name, the Status and the Country separated with the character "|".
The problem is that I have to get an element by only using the Project Name and the Country as parameters and there is no way to edit the HTML.
<li>Project 1 | approved | USA</li>
<li>Project 2 | approved | China</li>
<li>Project 3 | disapproved | Russia</li>
What I need is to remove the approved/disapproved text from the query, something like
//li[contains(text(),'Project 1 USA')]
Is there a way to achieve this using CSS or Xpath?
How about:
//li[contains(text(),'Project 1') and contains(text(),'USA')]
...if you are able to separate the project name and location?

How to write bullet list in markdown table?

I am trying to write a bullet list in markdown table, however I am unable to do so. I tried the solutions given here, and here.
I am writing the following table in bitbuckets readme.md file.
| **Date** | **A** | **B**
|:----------:|:-----:|:------:
| 2016 | Something | <ul><li>A</li><li>B</li><li>C</li></ul>
Every row of column B contains a bullet list of 2 items.
How can I achieve this ? What am I missing ? Please let me know. Thanks in advance.
I used the answer given by #Dorgrin in the post mentioned as a possible duplicate. Even while using that I was not able to get a list displayed. What I was shown was html code as plain text in the third column which is not the intended effect.
Bitbucket is lagging behind on supported features. Apparently they allow html in markdown README files, but they decided not to support it in snippets.
I say "apparently" because I just tried it, and it doesn't even work. See this repo.
I decided to ask them a question about this. You can follow further developments here
On a more positive note, what you had works well on Github as you can see here:
| **Date** | **A** | **B**
|:----------:|:-----:|:------:
| 2016 | Something | <ul><li>A</li><li>B</li></ul><ul><li>C</li></ul> |
<script src="https://gist.github.com/smac89/bc0ff6c7e41396293367b00df626317b.js"></script>
You can mimic the visual affect of a bulleted lists in a markdown table with the ascii character • and the <br> tag for a line break.
| | Apples | Oranges |
|-----------|--------|---------|
|attributes | • color: red <br> • shape: round | • color: orange <br> • shape: round |
|tasty | yes | yes |
Renders like this
I think this keeps the table clean of the html clutter from using the <li> and <ol>/<ul> tags.

Inline query for listing all pages from a namespace without any subobjects

I need an inline query that lists all pages from a specific namespace, but without listing subobjects specified on these pages.
Restricting results to a namespace is possible like that:
{{#ask: [[ExampleNamespace:+]] }}
But it lists all subobjects, too.
Workarounds:
Specify a category on these pages (subobjects don’t inherit it) and query for the category instead:
{{#ask: [[ExampleCategory]] }}
Specify a property on these pages (and never on the subobjects) and query for the property (with a wildcard value) instead:
{{#ask: [[ExampleProperty::+]] }}
But both workarounds require editing, which I would like to avoid. Is there a better way to solve this?
Not sure if it's a better way, but it looks like array formats/arrays and their #arraymap and #arrayunique functions are a way to go in order to trim SMW subobject tags and make the DISTINCT operation. Unfortunately, the solution below has a query result limit issue described as well (at least out of what I understand in SMW). In general, it may look like the following, and I will appreciate if someone suggests a nicer solution:
<!-- Fetch all pages from the "Live event" namespace -->
{{#arraydefine: QUERY_RESULT
| {{#ask: [[Live event:+]]
| format = array
| link = none <!-- NOTE: array item link -->
| limit = 10000 <!-- NOTE: limit -->
}}
}}
<!-- Store the mapped result into another array -->
{{#arraydefine: MAPPED_QUERY_RESULT
| {{#arraymap: {{#arrayprint: QUERY_RESULT}}
| ,
| $O <!-- NOTE: array map iterator value -->
| {{#explode: $O <!-- NOTE: explode by hash -->
| #
| 0
}}
}}
| ,
| unique
}}
<!-- Generate links markup -->
{{#arraymap: {{#arrayprint: MAPPED_QUERY_RESULT}}
| ,
| $O
| [[$O]] <!-- NOTE: plain links -->
}}
The notes from the code above:
NOTE: array item link - Not suppressing the links causes the mapper to be more complicated (including parsing HTML <span> tags and class attributes).
NOTE: limit - This is probably the biggest issue here as the number of subobjects affects the query result. SMW by default limits the query results, and the maximum query limit cannot be overridden as far as I know. Having more rows, which count is greater than the limits is, will cause the 'Further limits' link to appear. Actually speaking, I have no idea how to work around it nicely.
NOTE: array map iterator value - {{#arraymap}} seems to replace strings in the simplest way like sed or a simple text editor app do. So $O is used as the iterator value placeholder for the formula parameter trying not to clash with other string tokens.
NOTE: explode by hash - #ask subobject results generate hashed links like PageA#_159c1f213de2fcaf165f2c9c5c56686b. Just getting rid of them. In case you need to strip wiki links, you might also play around with [[ or | (encoded like [<nowiki/>[ and <nowiki>|</nowiki> respectively)
NOTE: plain links - The generated links will have underscores instead of spaces. Unfortunately, [[{{#replace: $O | _ | <nowiki> </nowiki>}}]] didn't work for me -- the underscores are simply consumed for some reason, however this approach is also recommended at the #replace function wiki page.
Some links:
SMW array result format
SMW configuration
SMW further results
#arraymap:
#explode:
#replace:
Help:List the set of unique values for a property (pay attention at the "Limitations and issues" section)