how to get the ouput of all paragraphs data in XSLT - xslt

This is my XML
<p>test1</p>
<p>test2<p>
<p>test3</p>
<p>test4</p>
HI here i have problem when working with for each loop to display the all paragraphs in above.
When i use forech loop for this,i am getting only the first value test1
Her is my code
<xsl:for-each select="root">
<xsl:value-of select="root/p"/>
</xsl:for-each>
out put is coming like this
test1
test1
test1
test1
Can any one give the solution for this .i will pleasure to them
Desired output
I want display like
test1
test2
test3
test4

Use:
<xsl:for-each select="root/p">
<xsl:value-of select="."/>
</xsl:for-each>

Related

How to append string values inside if condition

I am new to XSL.I have an XML as below, If CoverageCode equals -'HomeCoverage' then I have to verify for the next 3 elements of 'roofRestrictionEndt','sidingRestrictionEndt'and 'paintRestrictionEndt' . If 'roofRestrictionEndt' exits and its value is 'Y' then I need to print 'Roof' under the 'results' tag, If 'sidingRestrictionEndt' exists and its value is 'Y' then I need to print 'siding' in case if it exists along with the above one then I need to print 'Roof; siding'. If 'paintRestrictionEndt' exists and its value is 'Y' along with the other 2 elements then I need to print 'Roof; siding; paint'. I tried by declaring variables and wrote If conditions and tried to append values accordingly inside IF condition, but I came to know the declared variables are immutable. In java, we can achieve this by using StringBuffer. Is there any way to achieve this in XSL? Below is XML.
<locationCoverage ID="3">
<coverageCode >HomeCoverage</coverageCode>
<roofRestrictionEndt >Y</roofRestrictionEndt>
<sidingRestrictionEndt>Y</sidingRestrictionEndt>
<paintRestrictionEndt >Y</paintRestrictionEndt>
<locationCoverage>
Results should look like as below
<results>
<result>Roof;siding;paint</result>
</results>
If I have below input XML
<locationCoverage ID="3">
<coverageCode >HomeCoverage</coverageCode>
<roofRestrictionEndt >Y</roofRestrictionEndt>
<paintRestrictionEndt >Y</paintRestrictionEndt>
</locationCoverage>
For the above XML results should look like as below
<results>
<result>Roof;paint</result>
</results>
Appreciate it If anyone helps me with this. Thanks in advance.
If I understand this correctly (which is not at all certain), you want to do something like:
<xsl:template match="locationCoverage[coverageCode='HomeCoverage']">
<xsl:variable name="test-results">
<xsl:if test="roofRestrictionEndt='Y'">Roof </xsl:if>
<xsl:if test="sidingRestrictionEndt='Y'">siding </xsl:if>
<xsl:if test="paintRestrictionEndt='Y'">paint</xsl:if>
</xsl:variable>
<result>
<xsl:value-of select="translate(normalize-space($test-results), ' ', ';')"/>
</result>
</xsl:template>

Translate functions in xslt

Am having a code like this to translate from &amp; to & which is working fine, but it also removing other characters in the field which is a,m,p because we are translating.
I just want this to work to translate &amp; to & not to delete a,m,p characters.
<xsl:when
test="contains(//column[#name="Description"]/text(), "&amp;")">
<xsl:value-of
select="translate(//column[#name="Description"]/text(),'&amp;','& ')"
disable-output-escaping="no"/>
</xsl:when>
Input: Input: &amp;wUS &amp;and amptestamp
Current Output: &wUS &nd test
Expected output: &wUS &and amptestamp

Group the httpsamples if it has a specific substring in it

I Have a .jtl file which is the output of a jmeter run.
while generating the report, i want to group all samples under one thread if they have a substring "PASS".
Currently am trying the below code:
<xsl:for-each select="/testResults/*[not(#lb = preceding::*/#lb)]">
<xsl:variable name="label" select="substring-before(#lb,'#')" />
</xsl:for-each>
where
lb = PASS#US_Edit_make_year_VehicleName_model
lb = PASS#US_Edit_make_year_VehicleName_year
OutPut should be like:
PASS
->US_Edit_make_year_VehicleName_model
->US_Edit_make_year_VehicleName_year
But it is repeating twice since PASS is repeated twice.
please suggest
<xsl:for-each select="/testResults/*[not(#lb = preceding::*/#lb)]">
<xsl:variable name="label" select="substring-before(#lb,'#')" />
</xsl:for-each>
OutPut should be like
PASS
->US_Edit_make_year_VehicleName_model
->US_Edit_make_year_VehicleName_year
Output Got is:
PASS
->US_Edit_make_year_VehicleName_model
->US_Edit_make_year_VehicleName_year
PASS
->US_Edit_make_year_VehicleName_model
->US_Edit_make_year_VehicleName_year

Looping through an xpath getting the right iteration each time in xslt 2

I have a condition where I need to loop atleast once and so I have the following xsl code. However, this doesnt work as it always gets the last iterations value. How can I tweak this so it gets the right iteration on each loop?
<xsl:variable name='count0'>
<xsl:choose>
<xsl:when test='count($_BoolCheck/BoolCheck[1]/CheckBoolType) = 0'>
<xsl:value-of select="1"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select='count($_BoolCheck/BoolCheck[1]/CheckBoolType)'/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:for-each select="1 to $count0">
<xsl:variable name='_LoopVar_2_0' select='$_BoolCheck/BoolCheck[1]/CheckBoolType[position()=$count0]'/>
<e>
<xsl:attribute name="n">ValueIsTrue</xsl:attribute>
<xsl:attribute name="m">f</xsl:attribute>
<xsl:attribute name="d">f</xsl:attribute>
<xsl:if test="(ctvf:isTrue($_LoopVar_2_0/CheckBoolType[1]))">
<xsl:value-of select=""Value True""/>
</xsl:if>
</e>
</xsl:for-each>
The xml file is as follows:
<BoolCheck>
<CheckBoolType>true</CheckBoolType>
<CheckBoolType>false</CheckBoolType>
<CheckBoolType>1</CheckBoolType>
<CheckBoolType>0</CheckBoolType>
<CheckBoolType>True</CheckBoolType>
<CheckBoolType>False</CheckBoolType>
<CheckBoolType>TRUE</CheckBoolType>
<CheckBoolType>FALSE</CheckBoolType>
</BoolCheck>
In this case I need to iterate through each iteration of CheckBoolType and produce a corresponding number of values. However, in the above example if there were no CheckBoolType iterations I would still like the iterations to enter the for-each loop atleast once. i hope that clarifies it a little more.
First observation: your declaration of $count0 can be replaced by
<xsl:variable name="temp" select="count($_BoolCheck/BoolCheck[1]/CheckBoolType)"/>
<xsl:variable name="count0" select="if ($temp=0) then 1 else $temp"/>
(Sorry if that seems irrelevant, but my first step in debugging code is always to simplify it. It makes the bugs much easier to find).
When you do this you can safely replace the predicate [position()=$count0] by [$count0], because $count0 is now an integer rather than a document node. (Even better, declare it as an integer using as='xs:integer' on the xsl:variable declaration.)
But hang on, $count0 is the number of elements being processed, so CheckBoolType[$count] will always select the last one. That's surely not what you want.
This brings us to another bug in your code. The value of the variable $_LoopVar_2_0 is an element node named CheckBoolType. The expression $_LoopVar_2_0/CheckBoolType[1] is looking for children of this element that are also named CheckBoolType. There are no such children, so the expression selects an empty sequence, so the boolean test is always false.
At this stage I would like to show you some correct code to achieve your desired output. Unfortunately you haven't shown us the desired output. I can't reverse engineer the requirement from (a) your incorrect code, and (b) your prose description of the algorithm you are trying to implement.

iterating over parallel xml elements in xslt

<var>1</var>
<value>not null</value>
<var>2</var>
<value>00FFFFFFF555555000100673</value>
<var>3</var>
<value>9694r</value>
If it were a list of vars I can iterate like
<xsl:for-each select="var">
.. crap code
</xsl:for-each>
But I need to catch the value related to var whenever i catch the var ,and display it in a table. I guess this is bad design , but I'm knee deep.
You could try using:
<xsl:value-of select="following-sibling::value"/>
in place of "crap code".
You can use the following-sibling axis:
<xsl:for-each select="var">
<xsl:value-of select="./following-sibling::value[1]" />
</xsl:for-each>