Jump to content

Translating xml structure to an escaped string


michaelloveusa
 Share

Recommended Posts

So, I solved my previous problem of getting an xml encoded string out into an xml structure. Now I have to get a structure out into an escaped string (see the "manualAllocXML" element below): <s:element name="AllocatePayment"><s:complexType><s:sequence><s:element minOccurs="0" maxOccurs="1" name="securityToken" type="s:string" /><s:element minOccurs="1" maxOccurs="1" name="effPayDate" type="s:dateTime" /><s:element minOccurs="0" maxOccurs="1" name="manualAllocXml" type="s:string" /></s:sequence></s:complexType></s:element> I have the manualAllocXML in normal format as such: <manualalloc xmlns:xsi="http://www.w3.org/20...Schema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" resultdescr="test" resultstatus="0" xmlns="http://www.replaceme...mas/ManualAlloc"> <revobjs> <revobj dirtyreadchecksum="57" id="154917"/> <taxbills> <taxbill dirtyreadchecksum="57" id="1484553" revobjid="154917"/> </taxbills> </revobjs> <allocs> <alloc amount="5805.73" revobjid="271968" rolltype="1000002" revenuesource="290019" cd="0" subcd="0" taxbillid="6714081"/> </allocs></manualalloc> but I need to get it into an xml encoded string as such:

<manualalloc xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" resultdescr="test" resultstatus="0" xmlns="http://www.replaceme.com/schemas/ManualAlloc"><revobjs><revobj dirtyreadchecksum="57" id="154917"/><taxbills><taxbill dirtyreadchecksum="57" id="1484553" revobjid="154917"/></taxbills></revobjs><allocs><alloc amount="5805.73" revobjid="271968" rolltype="1000002" revenuesource="290019" cd="0" subcd="0" taxbillid="6714081"/></allocs></manualalloc>

Is there a clever way to do this? Thanks, Mike

Edited by michaelloveusa
Link to comment
Share on other sites

Still struggling with this. Here is what I have in my xsl:

  <xsl:param name="ManualAlloc"/>  <xsl:import href="http://lenzconsulting.com/xml-to-string/xml-to-string.xsl"/>  <xsl:output method="xml" cdata-section-elements="ManualAlloc"/>  <xsl:template match="/">    <xsl:apply-templates/>  </xsl:template>    <xsl:template match="@* | node()">    <xsl:copy>	  <xsl:apply-templates select="@* | node()"/>    </xsl:copy>  </xsl:template>   <xsl:template match="ManualAlloc">    <xsl:copy>	  <xsl:call-template name="xml-to-string">	    <xsl:with-param name="node-set" select="node()"/>	  </xsl:call-template>    </xsl:copy>  </xsl:template>

ManualAlloc is the param I want converted to a string (minus the CDATA designation). I am getting back exactly what I am putting in. Ideas? Mike

Edited by michaelloveusa
Link to comment
Share on other sites

Well what kind of parameter is that, are you passing in a node-set? Or which type does that parameter have?The xml-to-string takes a node or node-set and serializes it to a string.And of course if you pass a parameter in then the code needs to reference that parameter somewhere to make use of it so assuming you have a node-set parameter you need e.g.

<xsl:template match="/">  <xsl:call-template name="xml-to-string">    <xsl:with-param name="node-set" select="$ManualAlloc"/>  </xsl:call-template></xsl:template>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...