How to display same type of data from XML using XSLT
I am using XSLT and XML.
I have got below XML.
<documentCountryInformation>
<countryCode>US</countryCode>
<countryName>United States</countryName>
<sufficientDocumentation>Conditional</sufficientDocumentation>
<sectionInformation>
<sectionName>Health</sectionName>
<documentParagraph paragraphId="23628">
<paragraphType>Requirement</paragraphType>
<paragraphText>
<p>
Vaccination for
<strong>yellow fever</strong>
Persons without valid yellow fever certification, if required, are subject to quarantine for a period up to 6 days.
</p>
</paragraphText>
</documentParagraph>
</sectionInformation>
</documentCountryInformation>
<documentCountryInformation>
<countryCode>IN</countryCode>
<countryName>India</countryName>
<sufficientDocumentation>Conditional</sufficientDocumentation>
<sectionInformation>
<sectionName>Health</sectionName>
<documentParagraph paragraphId="23648">
<paragraphType>Requirement</paragraphType>
<paragraphText>
<p>
Vaccination for
<strong>Dengue fever</strong>
Persons without valid yellow fever certification, if required, are subject to quarantine for a period up to 3 days.
</p>
</paragraphText>
</documentParagraph>
</sectionInformation>
</documentCountryInformation>
Above is the part of full xml and you can see there are two records of same type, now开发者_如何转开发 I have got the <countryName>
in parameters of XSLT in above example my countryName parameter will contain this type of data "United States,India", Now I want to split the parameter data and further it will check the XML having same country name and display the data according, I mean there will be loop on country name and below is desired HTML.
<div class="resultsContainer" id="divTransit">
<h3>Transit - United States (US)</h3>
<p>
Vaccination for
<strong>yellow fever</strong>
Persons without valid yellow fever certification, if required, are subject to quarantine for a period up to 6 days.
</p>
<h3>Transit - India (IN)</h3>
<p>
Vaccination for
<strong>Dengue fever</strong>
Persons without valid yellow fever certification, if required, are subject to quarantine for a period up to 3 days.
</p>
</div>
Now I want to split the parameter data and further it will check the XML having same country name and display the data according, I mean there will be loop on country name and below is desired HTML.
There is no need to "split" the parameter value, nor for a "loop" of any kind.
This transformation:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:param name="pCountryName" select="'United States,India'"/>
<xsl:template match="/*">
<div class="resultsContainer" id="divTransit">
<xsl:apply-templates select=
"*[contains(concat(',',$pCountryName,','),
concat(',',countryName,',')
)
]
"/>
</div>
</xsl:template>
<xsl:template match="documentCountryInformation">
<h3>
<xsl:value-of select=
"concat('Transit - ',
countryName,
' (',
countryCode,
')'
)
"/>
</h3>
<xsl:copy-of select="*/*/paragraphText/node()"/>
</xsl:template>
</xsl:stylesheet>
when applied on the provided XML document (wrapped in a top element to become wellformed):
<t>
<documentCountryInformation>
<countryCode>US</countryCode>
<countryName>United States</countryName>
<sufficientDocumentation>Conditional</sufficientDocumentation>
<sectionInformation>
<sectionName>Health</sectionName>
<documentParagraph paragraphId="23628">
<paragraphType>Requirement</paragraphType>
<paragraphText>
<p>
Vaccination for
<strong>yellow fever</strong>
Persons without valid yellow fever certification, if required, are subject to quarantine for a period up to 6 days.
</p>
</paragraphText>
</documentParagraph>
</sectionInformation>
</documentCountryInformation>
<documentCountryInformation>
<countryCode>IN</countryCode>
<countryName>India</countryName>
<sufficientDocumentation>Conditional</sufficientDocumentation>
<sectionInformation>
<sectionName>Health</sectionName>
<documentParagraph paragraphId="23648">
<paragraphType>Requirement</paragraphType>
<paragraphText>
<p>
Vaccination for
<strong>Dengue fever</strong>
Persons without valid yellow fever certification, if required, are subject to quarantine for a period up to 3 days.
</p>
</paragraphText>
</documentParagraph>
</sectionInformation>
</documentCountryInformation>
</t>
produces the wanted, correct result:
<div class="resultsContainer" id="divTransit">
<h3>Transit - United States (US)</h3>
<p>
Vaccination for
<strong>yellow fever</strong>
Persons without valid yellow fever certification, if required, are subject to quarantine for a period up to 6 days.
</p>
<h3>Transit - India (IN)</h3>
<p>
Vaccination for
<strong>Dengue fever</strong>
Persons without valid yellow fever certification, if required, are subject to quarantine for a period up to 3 days.
</p>
</div>
You could have a template
<xsl:template match="documentCountryInformation[contains($countryName, countryName)]">
精彩评论