xml - Combining text values together using XSL -
i have xml file. snippet:
<?xml version="1.0" encoding="utf-8"?> <assignmenthistory> <w20160104> <studentitems> <item> <name counsel="13">name 1</name> <type>type 1</type> </item> </studentitems> </w20160104>
i wanting create xsl script works xml file. however, refers above external xml file using method:
<xsl:variable name="myxml" select "document('history.xml')"/>
in main xml file, in 'meeting' node has content:
<meetingdate day="7" dayshort="thu" dayfull="thursday" month="1" monthshort="jan" monthfull="january" year="2016"/>
what want do, combine @day, @month , @year attributes end "wyyyymmdd" can locate:
/assignmenthistory/wyyyymmdd
so can include values node in myxml in final output.
can please advise me how take attributes , convert them "wyyyymmdd"?
thank much.
thanks comments made progress. can format wyyyymmdd text value. struggling iterate external document:
<xsl:variable name="assignhistory" select="document('assignhistory.xml')"/> <xsl:variable name="y" select="meetingdate/@year"/> <xsl:variable name="m" select="format-number(meetingdate/@month, '00')"/> <xsl:variable name="d" select="format-number(meetingdate/@day, '00')"/> <xsl:variable name="week" select="concat('w',$y,$m,$d)"/> <xsl:value-of select="$week"/><br /> <xsl:for-each select="$assignhistory/assignmenthistory/*[name()=$week]/studentitems/item"> student (or assistant): <xsl:value-of select="name"/><br /> </xsl:for-each>
nothing showing.
this 1 possible way produce string in desired format "wyyymmdd"
:
<xsl:template match="meetingdate"> <xsl:variable name="y" select="@year"/> <xsl:variable name="m" select="format-number(@month, '00')"/> <xsl:variable name="d" select="format-number(@day, '00')"/> <xsl:variable name="name" select="concat('w',$y,$m,$d)"/> <xsl:value-of select="$name"/> </xsl:template>
output :
w20160107
xsl:variable
s used above split expression chunks make easier read. actual usage selecting target element xml document variable should :
<xsl:value-of select="$myxml/assignmenthistory/*[name()=$name]"/>
Comments
Post a Comment