0

I am going to create an ASP.NET user control (ascx) from input XML using xslt.

Because there is some strange design-agency html involved the output is not granted to be valid html or even xhtml, so telling from answers to my other question I need to use the output method text. The other reason is that when I use xml or html the output is cluttered with xmlns-attributes I cannot prevent without changing the output to text.

When the output would be XML, I would use a template like this:

<xsl:template match="TextField">
            <xsl:text>
                <![CDATA[<someInvalid><stuff><fromAgency /></somInvalid>]]>
            </xsl:text>
    <xsl:apply-templates select="./Label" />
    <asp:TextBox ID="{@id}" runat="server">
        <xsl:if test="@defaultValue">
            <xsl:attribute name="value">
                <xsl:value-of select="@defaultValue"/>
            </xsl:attribute>
        </xsl:if>
    </asp:TextBox>
            <xsl:text><![CDATA[</stuff>]]></xsl:text>
    <xsl:copy-of select="$br"/>
</xsl:template>

now, when I switch the output method to text, nothing is written to the result at all.

Obviously the text mode simply ignores all xml in the template. How can I tweak my template to output these elements even when the output method is set to text?

Clarification: The <asp:TextBox>- Tag with its attributes and values is the desired output of this transformation, but when changing output mode to text this is errantly ommited from the output.

Update: Here is a full input XML:

<?xml version="1.0" encoding="utf-8" ?>
<Form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="XmlForm.xsd">
   <Validation enabled="false" enableValidationSummary="true" />
   <FieldSet>
      <TextField id="firstInput" css-class="textfield-css-class" />
      <TextField id="secondInput" defaultValue="Wrdlbmrpft">
         <Label translatable="true" >Label Text</Label>
      </TextField>
   </FieldSet>
</Form>

The full desired output would be like this:

<%@ Control Language="C#" AutoEventWireup="true" Inherits="DevelopmentWeb.WebUserControl1" %>
<someInvalid><stuff><fromAgency /></somInvalid>
   <asp:TextBox runat="server" ID="firstInput" CssClass="textfield-css-class"></asp:TextBox>
</stuff>
<someInvalid><stuff><fromAgency /></somInvalid>
   <asp:Label runat="server" AssociatedControlID="secondInput">Label Text</asp:Label>
   <asp:TextBox runat="server" ID="secondInput">Wrdlbrmpft</asp:TextBox>
</stuff>
Community
  • 1
  • 1
Sebastian P.R. Gingter
  • 5,955
  • 3
  • 31
  • 73
  • Please show us the input XML and the desired output. Do not force us to guess or to look up other questions that you asked before. – mzjn Aug 19 '11 at 17:07
  • Added the requested information. – Sebastian P.R. Gingter Aug 19 '11 at 17:45
  • possible duplicate of [XSLT - how to put original XML into transformation result in text output mode](http://stackoverflow.com/questions/7270605/xslt-how-to-put-original-xml-into-transformation-result-in-text-output-mode) – Paul Sweatte May 25 '15 at 16:50

0 Answers0