Dynamically pass href in XML file
How can I dynamically specify a href value in a string
<?xml-stylesheet type="text/xsl" href="first.xsl"?> in xml?
I would like to dynamically replace "first.xsl".
Thanks for your help. =================== Apologies for spoiling this / making it difficult for you ====
My XML:
<?xml version="1.0" encoding="utf-8"?> <?xml-stylesheet type="text/xsl" href="first.xsl"?> <WinData records="1" fields="4"> <record id="1"> <Name type="82">January</Name> <Dept type="323">19</Dept> <InceptionDate type="82">01/01/2010</InceptionDate> <Salary type="645">3729.71</Salary> </record> <!-- Created from D:\AJAY\C#\VS2010\SBWA\XML --> </WinData> XSL:
<?xml version="1.0" encoding="ISO-8859-1"?> <!-- Edited by XMLSpy® --> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <body> <h2>Sub Selection of Data</h2> <table border="0"> <tr bgcolor="#9acd32"> <th>Name</th> <th>Dept</th> <th>InceptionDate</th> <th>Salary</th> </tr> <xsl:for-each select="WinData/record" > <xsl:sort select="./Name"/> <xsl:sort select="./Dept"/> <xsl:if test="Salary>100"> <tr> <td><xsl:value-of select="Name"/></td> <td><xsl:value-of select="Dept"/></td> <td><xsl:value-of select="InceptionDate"/></td> <td><xsl:value-of select="Salary"/></td> </tr> </xsl:if> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet> My specific tasks / tasks:
- How can I add the code snippet offered by iHeartGreek?
- Is there a way to pass the "replacement" xsl (newLink.xsl in the snippet) as a parameter?
Two possible solutions.
1) Two-pass conversion. You can output PI as follows:
<xsl:processing-instruction name="xml-stylesheet"> <xsl:value-of select="concat('type="text/xsl" href="', $whatever, '"')"/> </xsl:processing-instruction> 2) Use the "population" template (or "fill in the blanks", like Dimitriv calls), and metadata URIs to get the layout with fn:document() . See Dynamically Decide Which XSL Style Sheet to Use
Note : PI is part of the input tree. Whether this is an input tree from a parsed document or built by the DOM API or in any other way, for the XSLT processor there is only a “static” node of type “PI” with a “final” string value.
You can use an XSLT document to transform XML data.
Usage: (let's say node is called a "link")
<xsl:template match="link[.='first.xsl']"> <xsl:element name="link"> <xsl:text>newLink.xsl</xsl:text> </xsl:element> </xsl:template>