mercwrought
Programmer
Hi all, I’m new to xml and xslt. I’m more a SQL /vc6/c# kind of a guy. I’m working on displaying an xml file that has nested nodes. I have figured a few things out but I am now having trouble with templates. They make since but I don’t understand how to assignee the out put of one to a parameter.
Let me give you a something to work with and then ill ask some questions.
XML file
I don’t have a choice in the format of the xml it was provided in the specs. Basically it can continue as deep as it wants to go. So far I believe that I have figured out how to handle this. I will make a recursive template to work down the nodes transforming as I go. My problem (besides being new to xml and having really bad examples), I don’t know how to assign what a template would return to a xslt param.
I want to use the RepeateString template to create the path that I am checking. But I don’t know how to call the template from inside the select. I know xslt 2.0 has user defined function but I don’t know if 1.0 has and I need to keep this 1.0 friendly. Any ideas or questions.
Let me give you a something to work with and then ill ask some questions.
XML file
Code:
<Home>
<Room title="Red" description="Screen">
<Room title="Info" description="Main Info" url="~/PassInfo.aspx">
<Room title="Notes" description="Notes" url="~/NotesEdit.aspx"/>
</Room>
<Room title="Bath" description="I don’t know"/>
<Room title="Sink" description="I am running out of "/>
<Room title="Weapons arsenal" description="really bad examples">
<Room title="Pistol" description="ok I am out">
<Room title="357" description="mag"/>
</Room>
<Room title="Ak47" description="there are several types"/>
</Room>
</Room>
</Home>
I don’t have a choice in the format of the xml it was provided in the specs. Basically it can continue as deep as it wants to go. So far I believe that I have figured out how to handle this. I will make a recursive template to work down the nodes transforming as I go. My problem (besides being new to xml and having really bad examples), I don’t know how to assign what a template would return to a xslt param.
Code:
<xsl:template name="RecursiveRooms">
<xsl:param name="RLvl" select ="0"/>
<xsl:param name="RString" select ="fn:concat('Home/Room/Room',***RepeateString()***)"/>
<xsl:if test="">
<!-- Do work here -->
<!-- Move The next lvl deep -->
<xsl:call-template name="RecursiveRooms">
<xsl:with-param name="RLvl" select="$RLvl + 1"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
<xsl:template name="RepeateString">
<xsl:param name="count">0</xsl:param>
<xsl:if test="$count > 0">
<!-- Do work here -->
<xsl:value-of select="/Room"/>
<!-- Move The next lvl deep -->
<xsl:call-template name="RepeateString">
<xsl:with-param name="count" select="$count -1"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
I want to use the RepeateString template to create the path that I am checking. But I don’t know how to call the template from inside the select. I know xslt 2.0 has user defined function but I don’t know if 1.0 has and I need to keep this 1.0 friendly. Any ideas or questions.