Subject: Re: [xsl] XSLT to populate a SAML AttributeStatement from an XML From: "ohaya ohaya@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Wed, 18 Jan 2023 21:08:51 -0000 |
Hi, I originally thought that also but didn't know how to add the root to the XSLT (I tried just putting into the XSLT but it said that template had to be top-level). Anyway, so I was also guessing the problem was what you said, so I found a page the mentioned how to add the root and got this XSLT: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > <xsl:template match="/"> <saml:AttributeStatement> <xsl:apply-templates select="/record/adrRecord/*"/> </saml:AttributeStatement> </xsl:template> <xsl:template match="/record/adrRecord/PN_ID"> <saml:Attribute Name="MY_PN_ID" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic"> <saml:AttributeValue xmlns:xsd="http://www.w3.org/2001/XMLSchema" xsi:type="xsd:string"><xsl:value-of select="/record/adrRecord/PN_ID" /> </saml:AttributeValue> </saml:Attribute> </xsl:template> <xsl:template match="/record/adrRecord/personnel/ADM_ORG_CD"> <saml:Attribute Name="MY_ORG_CD" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic"> <saml:AttributeValue xmlns:xsd="http://www.w3.org/2001/XMLSchema" xsi:type="xsd:string"> <xsl:value-of select="/record/adrRecord/personnel/ADM_ORG_CD" /> </saml:AttributeValue> </saml:Attribute> </xsl:template> <xsl:template match="/record/adrRecord/personnel/DOD_ASSOC_CD"> <saml:Attribute Name="MY_ASSOC_CD" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic"> <saml:AttributeValue xmlns:xsd="http://www.w3.org/2001/XMLSchema" xsi:type="xsd:string"> <xsl:value-of select="/record/adrRecord/personnel/DOD_ASSOC_CD" /> </saml:AttributeValue> </saml:Attribute> </xsl:template> </xsl:stylesheet> I ran that with xsltproc and piped the output to xmllint, and now it is not complaining! Thanks, Jim P.S. This the page I found about how to add the root element: https://developer.mozilla.org/en-US/docs/Web/API/XSLTProcessor/Basic_Example but I was wondering: Is there a better way to accomplish that? Jim On Wednesday, January 18, 2023, 03:49:44 PM EST, Martin Honnen martin.honnen@xxxxxx <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote: On 1/18/2023 9:40 PM, ohaya ohaya@xxxxxxxxx wrote: > > When I run that with xsltproc I get: > > <?xml version="1.0"?> > > > <saml:Attribute xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Name="MY_PN_ID" > NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic"><saml:AttributeValue > xmlns:xsd="http://www.w3.org/2001/XMLSchema" > xsi:type="xsd:string">1111111</saml:AttributeValue></saml:Attribute> > > <saml:Attribute xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Name="MY_ORG_CD" > NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic"><saml:AttributeValue > xmlns:xsd="http://www.w3.org/2001/XMLSchema" > xsi:type="xsd:string">urn:NORM:DEPT</saml:AttributeValue></saml:Attribute> > <saml:Attribute xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > Name="MY_ASSOC_CD" > NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic"><saml:AttributeValue > xmlns:xsd="http://www.w3.org/2001/XMLSchema" > xsi:type="xsd:string">urn:NORM:V01</saml:AttributeValue></saml:Attribute> > > > > > > I don't know why there is that extra blank line after the first > <saml:Attribute>, but when I run xmllint --format I get: > > :6: parser error : Extra content at the end of the document > <saml:Attribute xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" xmlns:x > > > What "extra content" is it referring to? > > In the end your result XML document, like any XML document, is supposed to have single root element wrapping all other elements, I thought in your case e.g. <xsl:template match="/"><saml:statement><xsl:apply-templates/></saml:statement></xsl:template>
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] XSLT to populate a SAML A, Martin Honnen martin | Thread | Re: [xsl] XSLT to populate a SAML A, ohaya ohaya@xxxxxxxx |
Re: [xsl] XSLT to populate a SAML A, Martin Honnen martin | Date | Re: [xsl] XSLT to populate a SAML A, ohaya ohaya@xxxxxxxx |
Month |