Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
This is my school home work and can't figure it out myself.
I need to reformat an XML file from the input source to output XML using Transformation.
My input source has many tags (elements).
I have tags like this:
<tag>
<name>DOB</name>
<value>XX/XX/XX</value>
</tag>
<tag>
<name>Address</name>
<value>123 Main St.</value>
</tag>
and I need to transform these to
<DOB>xx/xx/xx</DOB>
<Address>123 Main St.</Address>
My teacher said use conditional but I don't think that is elegant way
to do it.
No, it's not. And what exactly would the condition be? You should try:
<xsl:template match="tag">
<xsl:element name="{name}">
<xsl:value-of select="value" />
</xsl:element>
</xsl:template>
Note that this will fail if the contents of name are not a valid XML name.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
https://xsltfiddle.liberty-development.net/eieFA1J/16
Here I am trying to match placeholder[#md.mnem='angen'][placeholder.text='UL'] and identify it's preceding <codes.head ID="" md.mnem="hg*"> and store it into variable. and collection all hg* records after that match until i find hg* record with same or smaller(in my example it is hg2, and if i find hg2 or hg1 i have to break the loop)
I am able to select the hg* records after a specific match but unable to break after matching same hg* or smaller one.
can anyone please help me to solve this, the xml and xsl can find in the below link.
https://xsltfiddle.liberty-development.net/eieFA1J/16
An XSLT 3 xsl:iterate instead of an xsl:for-each might help to implement the conventional loop and break algorithm:
<xsl:iterate select="$hgset">
<xsl:choose>
<xsl:when test="#md.mnem gt $hgValue">
<xsl:copy-of select="."/>
</xsl:when>
<xsl:otherwise>
<xsl:break/>
</xsl:otherwise>
</xsl:choose>
</xsl:iterate>
But of course you can also use a recursive function or template to implement the same in XSLT 2 or perhaps just select the first item in your sequence that "breaks" the condition and select anything "before" it with the << operator.
Another option is to use <xsl:for-each-group select="$hgset" group-ending-with="*[#md.mnem le $hgValue]"><xsl:if test="position() = 1"><xsl:copy-of select="current-group()"/></xsl:if></xsl:for-each-group>.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 3 years ago.
Improve this question
I have requirement of following reg-ex pattern:
Sample string :
<html> a test of strength and <h1> valour </h1> for <<<NOT>>> faint hearted <b> BUT </b> protoganist having their characters <<<CARVED>>> out of gibralter <b> ROCK </b>
This above is single string in which I want to strip out every HTML tag and retain <<<xyz>>> .
My attempt:
(^|\n| )<[^>]*>(\n| |$)
Can someone please critically review this ?
This is what I've come up with. It uses lookbehinds to make sure you identify hmtl tags by what will precede and follow them without actually including them in the match. The point is to look for < and > only if they are followed or preceded by spaces or letters (not other < or >). Is this what you are after or did I misread you?
(?=([ A-z]?))<{1}\/?[A-z1-6]+>{1}(?=[^>])
This question already has answers here:
RegEx match open tags except XHTML self-contained tags
(35 answers)
Closed 5 years ago.
I have an xml response in the following format
...
<field>
<fieldType>DOCUMENT</fieldType>
...
<fieldId>12345</fieldId>
<id>21345</id>
<isActive>F</isActive>
....
</field>
<field>
<fieldType>FOLDER</fieldType>
...
<fieldId>15345</fieldId>
<id>11345</id>
<isActive>T</isActive>
....
</field>
<field>
<fieldType>DOCUMENT</fieldType>
...
<fieldId>98765</fieldId>
<id>57689</id>
<isActive>T</isActive>
....
</field>
...
There are multiple such values in the xml. I need to extract only the fieldId
1. which is active i.e., T
2. which is of fieldType DOCUMENT.
I tried the following regex,
<fieldType>DOCUMENT</fieldType>.+?<fieldId>(.+?)</fieldId>.+?<isActive>T</isActive>
But this is extracting the 1st occurrence of fieldId, 12345 (even though it is not active) instead of 98765
P.s: I am trying to use this regex
An xml parser is probably a better solution. However based on your question this seems to achieve the desired output.
<fieldType>DOCUMENT<\/fieldType>\n.*\n.*<fieldId>(.*)<\/fieldId>.*\n.*\n.*<isActive>T<\/isActive>/g
Try it here! https://regexr.com/3krn4
This question already has answers here:
Why it's not possible to use regex to parse HTML/XML: a formal explanation in layman's terms
(10 answers)
Closed 5 years ago.
I have a xml file with this data format
<row Id="9" Body="aaaaaaaaa" Target="123456" />
I want to find & replace all Body="" things with a space from my xml file. What is the regex for that?
There are many possibilities, here is one way to remove the content from the Body attribute
(<row.*Body=").*?("[^>]+>)
This creates two capturing groups for the content before and after the Body attribute. Then, you just use those capturing groups for the replacement:
$1$2
It will transform:
<row Id="9" Body="aaaaaaaaa" Target="123456" />
Into:
<row Id="9" Body="" Target="123456" />
You can see it working here.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
Iam looking to way to find and replace multiple occurances of opening <table > tag using regex
tag have different patterns between <> and need to select only characters within opening tag - not between
<table i need to select this> i dont want select this one </table>
no language specified - i need to replace whole content opening table tag to <table class="table-responsive"> in sql file
If this is a one-off replacement, regex will be fine. As long as there are not > inside the attributes of the opening tag, you can use this to select opening tags:
<table[^>]*>